uni-app 4.52版本鸿蒙真机运行,发现uni.chooseImage选择图片后得到的文件临时路径,通过image组件无法正常加载,网络图片正常
问题描述
uni-app 4.52版本鸿蒙真机运行,发现uni.chooseImage选择图片后得到的文件临时路径,通过image组件无法正常加载,网络图片正常;这种问题应该如何处理
8 回复
临时解决方法:把附件的UniAppRuntime.har 放到 harmony-configs 目录下的 libs 目录在,删除 unpackage 之后重新运行
更多关于uni-app 4.52版本鸿蒙真机运行,发现uni.chooseImage选择图片后得到的文件临时路径,通过image组件无法正常加载,网络图片正常的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
实测 4.45版本正常,使用4.52版本就有问题
感谢反馈,正在查找问题原因
回复 DCloud_UNI_yuhe: 解决了以后,麻烦@下
回复 ujoin_wql: 可以关注一下这个问题
回复 DCloud_UNI_yuhe: 已经关注了
这是一个典型的路径访问权限问题。在鸿蒙系统上,uni.chooseImage返回的临时路径可能受到系统安全限制导致无法直接访问。
解决方案建议:
- 使用uni.getFileSystemManager() API将临时文件保存到应用可访问的目录:
const fs = uni.getFileSystemManager();
const savedFilePath = `${wx.env.USER_DATA_PATH}/${Date.now()}.jpg`;
fs.saveFile({
tempFilePath: res.tempFilePaths[0],
filePath: savedFilePath,
success: () => {
this.imagePath = savedFilePath;
}
});
- 或者使用base64方式处理:
uni.getFileSystemManager().readFile({
filePath: res.tempFilePaths[0],
encoding: 'base64',
success: (r) => {
this.imageSrc = 'data:image/jpeg;base64,' + r.data;
}
});