uniapp使用uni.downloadFile下载客户端传过来的文件地址,我是.docx,但是下载之后变成了.pdf
export const saveFile=(url,open=true)=>{
url = encodeURI(url)
console.log('ccc', url)
// return
return new Promise((resolve,reject)=>{
uni.downloadFile({
url,
//
success: function (res) {
console.log(res)
uni.saveFile({
tempFilePath:res.tempFilePath,
success: function (res) {
console.log('保存成功')
console.log(res)
let {savedFilePath}=res
let tipContent=open ? `文件保存成功,保存路径 ${savedFilePath},是否打开?` : `文件保存成功,保存路径 ${savedFilePath}`
if(open){
showConfirm(tipContent).then(confirm=>{
uni.showLoading({title:'正在打开'})
uni.openDocument({
filePath:savedFilePath,
fileType:'docx',
success: function (openRes) {
resolve(savedFilePath)
},
complete:function (){
uni.hideLoading()
}
})
})
}else{
showAlert(tipContent)
}
},
fail:function (err){
console.log('保存失败')
console.log(err)
showAlert('保存失败',err)
reject(err)
},
complete:function (){
uni.hideLoading()
}
})
},
fail:function (err){
reject(err)
},
complete:function (){
uni.hideLoading()
}
})
})
}
这里第一次打印url都还是doc文件,但是经过downloadFile success(res)里却变成了 pdf文件
attachment; filename="xxx.docx"