uni-app HBuilder X更新版本后安卓附件下载打开失败
uni-app HBuilder X更新版本后安卓附件下载打开失败
| 开发环境 | 版本号 | 项目创建方式 |
|---|---|---|
| Windows | HBuilderX | |
| windows10 | ||
| HBuilderX | 3.2.3 | |
| Android | 9.0 | |
| 手机厂商 | ||
| 华为 | ||
| 手机机型 | ||
| mate 20 | ||
| 页面类型 | ||
| vue | ||
| 打包方式 | ||
| 云端 |
示例代码:
uni.downloadFile({
url:decodeURIComponent(erpurl),
success: function(res) {
if(uni.getSystemInfoSync().platform=='ios'){
uni.openDocument({
filePath: res.tempFilePath,
success: function() {
uni.hideLoading();
},
fail: function() {
uni.hideLoading();
uni.showToast({
icon: 'none',
title: '文件预览失败,请下载后打开'
});
}
})
}else{
uni.openDocument({
filePath:res.tempFilePath,
success: function() {
uni.hideLoading();
},
fail: function() {
uni.hideLoading();
uni.showToast({
icon: 'none',
title: '文件预览失败,请下载后打开'
});
}
})
}
},
fail: function() {
uni.hideLoading();
uni.showToast({
icon: 'none',
title: '文件下载出错!'
});
}
})
操作步骤:
- 附件下载打开无反应
预期结果:
- 附件成功打开
实际结果:
- 附件未打开
bug描述:
安卓真机联调打包,附件打开无反应,走了success方法,返回openDocument:ok,但是附件并未打开,无任何反应
更多关于uni-app HBuilder X更新版本后安卓附件下载打开失败的实战教程也可以访问 https://www.itying.com/category-93-b0.html
之前版本是否正常?
更多关于uni-app HBuilder X更新版本后安卓附件下载打开失败的实战教程也可以访问 https://www.itying.com/category-93-b0.html
正常
回复 4***@qq.com: 附上测试用的文件网址,换其他文件网址试试
回复 DCloud_UNI_GSQ: 我换成我外网服务器地址就下下来了http://110.56.63.54:8085/upload/appPackage/测试.xlsx 内网这个地址http://xxxxxx/console/file/hrDownloadFile?force=true&uris=/data/vm-oa/file/hr/20210918/2384/B2B/(001-通用附件)2020年度公司公司公司公司公司公司公司公司公司公司公司.docx就打不开,但是浏览器直接访问可以下载
回复 4***@qq.com: iOS 是否正常?
回复 DCloud_UNI_GSQ: 正常,我这边排查了一下,应该是?这个符号导致的,我临时下载文件夹里文件名只到?前面的hrDownloadFile,而且没有文件后缀,我手动加上.后面文件后缀就打开了
根据你的描述,在HBuilderX 3.2.3版本下,安卓9设备(华为Mate 20)上使用uni.downloadFile下载文件后,调用uni.openDocument虽然返回成功(openDocument: ok),但实际文件并未打开。这通常与文件路径、文件类型或系统权限有关。
核心排查点如下:
- 文件路径与存储权限:从HBuilderX 3.0+开始,安卓平台对文件存储和访问权限的管理更为严格。
downloadFile下载的文件默认保存在应用内部存储目录,openDocument可能无法直接访问。建议使用uni.saveFile将文件保存到用户可访问的公共目录(如uni.env.USER_DATA_PATH)后再尝试打开。// 在downloadFile的success回调中 uni.saveFile({ tempFilePath: res.tempFilePath, success: function (saveRes) { uni.openDocument({ filePath: saveRes.savedFilePath, // 使用保存后的路径 success: function () { uni.hideLoading(); }, fail: function (err) { console.error('openDocument fail:', err); uni.hideLoading(); } }); } });

