后台接口返回流文件,若是H5可以直接window.open打开该接口
但是post请求的话 只能请求时responseType: blob 对返回数据进行处理了 特别是app
后端若是返回的文件流 没有做type区分 这边需要各自单独处理下
文件后缀 | blob对应的type |
---|---|
.doc | application/msword |
.docx | application/vnd.openxmlformats-officedocument.wordprocessingml.document |
.xls | application/vnd.ms-excel |
.xlsx | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet |
.txt | text/plain |
application/pdf |
处理转换
const blob = new Blob([data], { type: type })
blob.lastModifiedDate = new Date()
blob.name = fileName
saveAs(blob, fileName)
cordova app打开文件时 记得加好文件后缀 如何打开 上篇文章有记录
dirEntry.getFile(fileName, { create: true, exclusive: false }, fileEntry =>
fileName 是带后缀的文件名
若同一接口返回不同文件流 记得把type加上哦