download:function(e,index){
var that=this;
//#ifdef H5
// uni.hideLoading()
window.location.href=admin.host+"approvalFormData/downloadFile/"+e
//#endif
//#ifndef H5
uni.showLoading()
uni.downloadFile({
url: admin.host+"approvalFormData/downloadFile/"+e,
success: (res) => {
console.log(res)
uni.saveFile({
tempFilePath: res.tempFilePath,
success: function (resx) {
var downlists=that.downlist
downlists=downlists.filter(function(item){
return item.id != e
})
downlists.push({id:e,filePath:resx.savedFilePath})
var listarray=that.listarray
console.log(resx.savedFilePath)
listarray[index].filePath=resx.savedFilePath;
listarray[index].zhuantai=true;
that.listarray = listarray
uni.setStorage({
key:'spfj' + that.spid,
data: downlists,
success: function () {
uni.hideLoading()
}
});
},fail(resx) {
console.log(resx)
}
});
},
fail:(res) => {
console.log(res)
}
});
//#endif
}
- 发布:2021-03-09 09:23
- 更新:2021-03-09 09:23
- 阅读:1513
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: WIN10
HBuilderX类型: 正式
HBuilderX版本号: 3.1.4
手机系统: Android
手机系统版本号: Android 10
手机厂商: 华为
手机机型: MATE20
页面类型: vue
打包方式: 云端
项目创建方式: HBuilderX
示例代码:
操作步骤:
下载 以该名称命名的图片1612660462400_src=http_a2.att.hudong.com_86_1001300000184180121920108394217.jpg&refer=httpa2.att.hudong.jpg
下载 以该名称命名的图片1612660462400_src=http_a2.att.hudong.com_86_1001300000184180121920108394217.jpg&refer=httpa2.att.hudong.jpg
预期结果:
{
"tempFilePath": "_doc/uniapp_temp_1615252340096/download/1612660462400_src=http_a2.att.hudong.com_86_1001300000184180121920108394217.jpg&refer=httpa2.att.hudong.jpg",
"statusCode": 200,
"errMsg": "downloadFile:ok"
}
{
"tempFilePath": "_doc/uniapp_temp_1615252340096/download/1612660462400_src=http_a2.att.hudong.com_86_1001300000184180121920108394217.jpg&refer=httpa2.att.hudong.jpg",
"statusCode": 200,
"errMsg": "downloadFile:ok"
}
实际结果:
错误返回
{
"tempFilePath": "_doc/uniapp_temp_1615252340096/download/1612660462400_src",
"statusCode": 200,
"errMsg": "downloadFile:ok"
}
错误返回
{
"tempFilePath": "_doc/uniapp_temp_1615252340096/download/1612660462400_src",
"statusCode": 200,
"errMsg": "downloadFile:ok"
}
bug描述:
uni.downloadFile 下载文件,当文件名称内包含 = .等特殊字符。会导致下载成功后的tempFilePath 缺失,导致文件无法打开
该文件名称为:
1612660462400_src=http_a2.att.hudong.com_86_1001300000184180121920108394217.jpg&refer=httpa2.att.hudong.jpg
错误返回
{
"tempFilePath": "_doc/uniapp_temp_1615252340096/download/1612660462400_src",
"statusCode": 200,
"errMsg": "downloadFile:ok"
}
0 个回复