uniappx uni.downloadFile({
url: item.fullurl,
success: (res) => {
uni.hideLoading()
console.log(res)
if (res.statusCode === 200) {
const filePatha = res.tempFilePath
console.log(filePatha)
uni.openDocument({
filePath: filePatha,
success: () => {
console.log('打开文档成功'+filePatha)
},
fail: (err) => {
console.log('打开失败'+err)
uni.showToast({ title: '打开失败:' + err.errMsg, icon: 'none' })
}
})
} else {
uni.hideLoading()
uni.showToast({ title: '下载失败', icon: 'none' })
}
},
fail: (err) => {
uni.hideLoading()
uni.showToast({ title: '下载失败:' + err.errMsg, icon: 'none' })
}
})
- 发布:16 分钟前
- 更新:4 分钟前
- 阅读:14
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: 10
HBuilderX类型: 正式
HBuilderX版本号: 5.24
手机系统: Android
手机系统版本号: Android 16
手机厂商: 三星
手机机型: s24+
页面类型: vue
vue版本: vue3
打包方式: 云端
项目创建方式: HBuilderX
示例代码:
操作步骤:
uni.downloadFile({
url: item.fullurl,
success: (res) => {
uni.hideLoading()
console.log(res)
if (res.statusCode === 200) {
const filePatha = res.tempFilePath
console.log(filePatha)
uni.openDocument({
filePath: filePatha,
success: () => {
console.log('打开文档成功'+filePatha)
},
fail: (err) => {
console.log('打开失败'+err)
uni.showToast({ title: '打开失败:' + err.errMsg, icon: 'none' })
}
})
} else {
uni.hideLoading()
uni.showToast({ title: '下载失败', icon: 'none' })
}
},
fail: (err) => {
uni.hideLoading()
uni.showToast({ title: '下载失败:' + err.errMsg, icon: 'none' })
}
})
uni.downloadFile({
url: item.fullurl,
success: (res) => {
uni.hideLoading()
console.log(res)
if (res.statusCode === 200) {
const filePatha = res.tempFilePath
console.log(filePatha)
uni.openDocument({
filePath: filePatha,
success: () => {
console.log('打开文档成功'+filePatha)
},
fail: (err) => {
console.log('打开失败'+err)
uni.showToast({ title: '打开失败:' + err.errMsg, icon: 'none' })
}
})
} else {
uni.hideLoading()
uni.showToast({ title: '下载失败', icon: 'none' })
}
},
fail: (err) => {
uni.hideLoading()
uni.showToast({ title: '下载失败:' + err.errMsg, icon: 'none' })
}
})
预期结果:
弹出其他可以打开的APP
弹出其他可以打开的APP
实际结果:
毫无反应 不报错
毫无反应 不报错
bug描述:
uniappx uni.downloadFile({
url: item.fullurl,
success: (res) => {
uni.hideLoading()
console.log(res)
if (res.statusCode === 200) {
const filePatha = res.tempFilePath
console.log(filePatha)
uni.openDocument({
filePath: filePatha,
success: () => {
console.log('打开文档成功'+filePatha)
},
fail: (err) => {
console.log('打开失败'+err)
uni.showToast({ title: '打开失败:' + err.errMsg, icon: 'none' })
}
})
} else {
uni.hideLoading()
uni.showToast({ title: '下载失败', icon: 'none' })
}
},
fail: (err) => {
uni.hideLoading()
uni.showToast({ title: '下载失败:' + err.errMsg, icon: 'none' })
}
}) 下载成功/data/data/io.aaa/cache/uni-download/1_1788265752981223(12).pdf 打不开 毫无反应,也不报错
2 个回复
Ask小助手
感谢您的反馈。针对您提交的 Bug,我们已进行评审分析,具体评估如下:
1. Bug 反馈内容完整性评审
.uvue页面,缺少<template>及相关上下文,需官方人员补充页面框架后才能运行。item.fullurl的具体值缺失),可能导致官方人员无法直接验证,建议补充真实可用的链接。2. Bug 是否成立分析
uni-app x在 Android 平台支持uni.openDocument。官方示例代码在调用时,fail回调中使用了err.errCode,而您的代码中使用的是err.errMsg。在uni-app x的强类型约束下,若错误对象结构不匹配,可能导致异常被静默吞掉。uni.downloadFile成功后,直接将res.tempFilePath传入uni.openDocument的filePath,并在失败回调中输出err.errCode。建议您先参考官方示例修正错误回调的字段名称。.uvue页面代码及可复现的文件 URL,以便进一步排查是否为特定机型或系统版本下的兼容性问题。5***@qq.com (作者)
基座要重新打包
要回复问题请先登录或注册
公告
更多>相关问题