uni.request({标签:uniapp,文件,res,application,let,data,pdfData,datas,图片 From: https://www.cnblogs.com/anans/p/16629370.html
url: '*****', //仅为示例,并非真实接口地址。
method: 'GET',
responseType: 'arraybuffer',
data: {
},
header: {
'content-type': 'application/json',
'token': 'token'
},
success: (res) => {
// 返回的是文件流
let datas = res.data
let blob = new Blob([ datas], {
type: 'application/pdf;charset=UTF-8'
})
let pdfData = window.URL.createObjectURL(blob) //创建预览路径
let agreementUrl = encodeURIComponent(pdfData)
let codeImg = 'data:image/png;base64,' + btoa(
new Uint8Array(datas).reduce((datas, byte) => datas + String.fromCharCode(byte), '')
);
}
});