当前位置: 首页 > news >正文

文件流导出文件

// 下载excel
export const downloadFile = (fileStream, fileName) => {if (window.navigator.msSaveBlob) {try {window.navigator.msSaveBlob(fileStream, fileName);} catch (e) {console.log(e);}} else {const url = window.URL || window.webkitURL;const bUrl = url.createObjectURL(fileStream);let a = document.createElement("a");a.style.display = "none";a.href = bUrl;a.download = decodeURIComponent(fileName);document.body.appendChild(a);a.click();document.body.removeChild(a);url.revokeObjectURL(bUrl);}
};

使用downloadFile(res, `默认文件.xlsx`);

res是后端返回文件流,默认文件.xlsx是文件名   .xlsx是后缀名

// 获取文件类型
export function getFileType(file) {const type = file.type || "";const name = file.name || "";if (type.includes("word")) {return "doc";} else if (type.includes("excel") || type.includes("spreadsheetml.sheet")) {return "excel";} else if (type === "text/plain") {return "txt";} else if (type === "application/pdf") {return "pdf";} else if (type === "text/html") {return "html";} else if (type === "text/markdown" || name.includes(".md")) {return "md";} else {return "other";}
}

http://www.dtcms.com/a/285798.html

相关文章:

  • 小米深圳大厦正式开园,为全球化竞争注入新动能
  • Golang 中 JSON 和 XML 解析与生成的完全指南
  • 一段黄昏小感
  • Linux地址空间
  • 论文分享 | LABRADOR:响应引导的针对物联网设备的黑盒模糊测试
  • 基于ASP.NET+SQL Server的网站登录注册功能设计与实现
  • 软件工程中的《资本论》
  • 文档处理控件TX Text Control系列教程:使用 C# .NET 将二维码添加到 PDF 文档
  • stack and queue 之牛刀小试
  • 【LeetCode 热题 100】199. 二叉树的右视图——(解法一)BFS
  • PDF批量拆分、合并、转图、加密一站式解决方案
  • 文件上传 ,显示文件列
  • 区别下IO多路复用,reactor,事件循环(EventLoop),Epoll这几个的概念以及之间的关系
  • uni-app 跳转外部连接
  • JS获取 CSS 中定义var变量值
  • Android性能优化之网络优化
  • LangChain 源码剖析(三):连接提示词与大语言模型的核心纽带——LLMChain
  • Jmeter使用教程
  • 闭包的定义和应用场景
  • [安洵杯 2019]easy_web
  • 深度学习×第10卷:她用一块小滤镜,在图像中找到你
  • DOM 文档对象模型
  • 【移动端知识】移动端多 WebView 互访方案:Android、iOS 与鸿蒙实现
  • Esbuild-新一代极速前端构建打包工具
  • 基于单片机多功能称重电子称设计
  • 前端下载文件并按GBK编码解析内容
  • C#`Array`进阶
  • Java全栈面试实录:从Spring Boot到AI大模型的深度解析
  • 现代R语言机器学习:Tidymodel/Tidyverse语法+回归/树模型/集成学习/SVM/深度学习/降维/聚类分类与科研绘图可视化
  • 135. Java 泛型 - 无界通配符