首页 > 其他分享 >关于文件下载的封装

关于文件下载的封装

时间:2023-09-22 14:33:24浏览次数:40  
标签:文件 elink res 封装 blob const message data 下载

import axios from 'axios' const isIE = () => navigator.userAgent.toLowerCase().indexOf('trident') > -1;  //判断是否为IE浏览器 // 文件下载 export async function downLoad(params) {     // return request('/ability/api/rs/gw/file/' + params.id, {     //     method: 'get',     // })     return axios({ // 用axios发送post请求         method: 'get',         url: '/ability/api/rs/gw/file/' + params.id,         // url: `/api/v4/idc_settlement/${data.tag}/exportExcel`, // 请求地址         data: {}, // 参数         responseType: 'blob', // 表明返回服务器返回的数据类型         headers: {             'Content-Type': 'application/json',             'token': token,             'Authorization': token         }     }).then(res => {         console.log(res);         // if (res.data.type == 'application/vnd.ms-excel' || res.data.type == 'application/vnd.ms-excel;charset=UTF-8') {         //     const blob = new Blob([res.data], { type: 'application/vnd.ms-excel' });         //     const fileName = decodeURI(res.headers['content-disposition'].split('filename=')[1]);         if (res.status == 200) {             const fileName = params.name;             const blob = new Blob([res.data], { type: 'application/vnd.ms-excel' });             if (isIE()) {                 window.navigator.msSaveOrOpenBlob(blob, fileName);                 // message.success('导出成功');             } else {                 const elink = document.createElement('a');                 elink.id = 'testPrint1'                 elink.download = fileName;                 elink.style.display = 'none';                 elink.href = URL.createObjectURL(blob);                 document.body.appendChild(elink);                 elink.click();                 URL.revokeObjectURL(elink.href); // 释放URL 对象                 document.body.removeChild(elink);                 // message.success('导出成功');             }         } else {             message.error('导出失败,请查看是否存在数据')         }
        // } else {         //     message.error('导出失败,请查看是否存在数据')         // }     })
    // .catch(err => {     //     message.error('导出失败')     // }); }

标签:文件,elink,res,封装,blob,const,message,data,下载
From: https://www.cnblogs.com/yuan947022015/p/17722290.html

相关文章

  • vue3 将文件集合下载后导出zip文件
    //注意:文件的url一定是服务器上的地址如http:xxxx//先下载npmijszipfile-saver//封装importJSZipfrom'jszip'importFileSaverfrom'file-saver'constgetFile=(url)=>{returnnewPromise((resolve,reject)=>{//通过请求获取文件blob格式......
  • 小米云原生文件存储平台化实践:支撑 AI 训练、大模型、容器平台多项业务
    小米作为全球知名的科技巨头公司,已经在数百款产品中广泛应用了AI技术,这些产品包括手机、电视、智能音箱、儿童手表和翻译机等。这些AI应用主要都是通过小米的深度学习训练平台完成的。在训练平台的存储方案中,小米曾尝试了多种不同的存储方式,包括Ceph+NFS、HDFS和对象存储挂......
  • 利用Python从现有的Excel表格中复制指定列生成新的Excel文件
    importxlrdimportxlwtimportpatternsaspatternsfile1='通讯专线汇总统计表.xls'file2='附件:历史存量邮电费明细.xls'data1=xlrd.open_workbook(file1)table1=data1.sheet_by_index(0)nrows1=table1.nrowszx_infos=[]#读取“通讯专线汇总统计表.xls”文件中......
  • 手动下载并安装 PHP 和 WinCache
    https://learn.microsoft.com/zh-cn/iis/application-frameworks/scenario-build-a-php-website-on-iis/configuring-step-1-install-iis-and-php手动下载并安装PHP和WinCache打开浏览器到 WindowsforPHP下载页 并下载PHP非线程安全zip包。从 适用于PHP的......
  • C# 指定物理目录下载文件,Response.End导致“正在中止线程”异常的问题
    https://blog.51cto.com/u_15116285/5964873https://blog.csdn.net/phphot/article/details/4211921https://www.codenong.com/20988445/https://www.dbmng.com/art-2500.html现象:通过浏览器下载pdf文件,下载可以正常下载,可是却会抛出异常,提示正在中止线程。查了资料,能看懂的......
  • Windows和Linux中的库、对象、可执行文件后缀名
    中国软件工程师面试常问的问题Justa"Scientific"(Interview)ExplanationforInterviewProblemsforSoftwareEngineers(mostChineseInterviews)Windows和Linux中的库、对象、可执行文件后缀名library,object,executablefilessuffixnameinWindowsandLinuxL......
  • geoserver下载安装及使用全过程
    GeoServer是OpenGISWeb服务器规范的J2EE实现,利用GeoServer可以方便的发布地图数据,允许用户对特征数据进行更新、删除、插入操作,通过GeoServer可以比较容易的在用户之间迅速共享空间地理信息。注:GeoServer的是一个基于Java的软件,安装前请确认本地的java环境。若未安装......
  • 投标文件编写经验--陪标
    1、拷贝(目标文件-源文件)尽量标题序号对应,调格式不好调2、样式:粘贴(只粘贴文本),再应用样式调格式3、*偏离项:如果内容无相关项,可以把原文件拷贝过来,放到相关内容下盖帽展示。......
  • 04_拖动文件渲染在页面中
      新建一个文件夹,跟之前一样,在Vscode终端里输入yarncreateelectron-appDrag。  在index.html添加以下代码,JS文件夹和render.js都是新创建的:  首先,css文件一般和html结合使用,相当于html是结构,而css是样式。在index.css添加以下代码:  在index.js......
  • 已解决pandas无法读取中文文件的问题
    已解决pandas无法读取中文文件的问题文章目录报错问题解决方法声明报错问题之前在工作中遇到过这个坑,记录一下问题以及解决方法,不一定针对所有情况都能用,但是可以供大家参考。问题描述如下:pandas无法读取中文文件的问题文件有问题或者环境编码有问题!解决方法data=open(r'dataset......