zoukankan      html  css  js  c++  java
  • 后台管理系统文件三部曲之——第二部曲实现文件的下载

    文件下载的实现,这个点在做的时候调用到了技术中台的接口

    //  影像上传下载接口调技术中台的
    export function getDownUrl(objectId) {
        return requestExport({
          url: `/tc-storage-service/obj/storage/download?objectId=${objectId}`,
          method: 'get'
        })
      }

    js代码实现

    //  下载影像上传的文件
        downLoad(id, name) {
          const fileName = name;
          if (id) {
            getDownUrl(id)
              .then((res) => {
                const link = document.createElement("a");
                const blob = new Blob([res]);
                var reader = new FileReader();
                reader.readAsText(blob, "utf-8");
                reader.onload = () => {
                  if (window.navigator && window.navigator.msSaveOrOpenBlob) {
                    navigator.msSaveBlob(blob);
                  } else {
                    link.style.display = "none";
                    link.href = URL.createObjectURL(blob);
                    link.setAttribute("download", fileName);
                    document.body.appendChild(link);
                    link.click();
                    document.body.removeChild(link);
                  }
                };
              })
              .catch((error) => {
                console.log(error);
              });
          } else {
            this.$message({
              type: "error",
              message: "请传文件路径!",
            });
          }
        },
  • 相关阅读:
    SpringMVC文件下载
    Servlet3.0文件上传
    SpringMVC拦截器的使用(入门)
    SpringMVC文件上传
    SpringMVC后台数据校验
    SpringMVC@InitBinder使用方法
    C++ this指针
    C++ 析构函数
    C++ 构造函数
    C++ 成员函数的实现
  • 原文地址:https://www.cnblogs.com/Ky-Thompson23/p/13825599.html
Copyright © 2011-2022 走看看