前置条件:
环境:
编辑器: HBuilder X4.71-alpha
鸿蒙手机: nova 13
软件版本: 5.0.1.120
步骤:
1、fileSystemManager = uni.getFileSystemManager();
2、先选取图片后获取地址,再用 fileSystemManager.readFileSync读取图片,报错: readFileSync:fail filePath No such file or directory;代码如下:
chooseMedia() {
uni.chooseMedia({
count: 1,
mediaType: ['image'],
sourceType: ['album'],
success: (res) => {
this.tempFilePath = res.tempFiles[0].tempFilePath;
try {
fileSystemManager.readFileSync(res.tempFiles[0].tempFilePath);
} catch(err) {
console.log('readFileSync', err) //
}
},
fail: (err) => {
console.log('chooseMedia', err);
}
})
},
3、错误信息:readFileSync:fail filePath No such file or directory
小帅008
还是提示 readFile:fail filePath No such file or directory Invalid argument ,使用的是 ,代码片段 uni.chooseImage({
count: count,
sizeType: sizeType,
sourceType: sourceType,
success(res) {
const path = res.tempFilePaths[0];
uni.getFileSystemManager().readFile({
filePath: path, // 选择图片返回的相对路径
encoding: "base64", // 编码格式
success: (res) => {
console.log("data:image/png;base64," + res.data); // 完整的base64字符串,包含mime和编码数据
},
fail(err) {
console.log("------------------------>>>>>>", err);
console.log("------------------------>>>>>>", res.tempFilePaths[0]);
},
});
},
2025-09-16 09:13
DCloud_UNI_yuhe
回复 b***@163.com: 删除了unpackage之后重新运行之后尝试一下呢?我这里测试是正常的
2025-09-16 11:02
小帅008
回复 DCloud_UNI_yuhe: 我使用的是 uniapp x ,目录结构我贴在最下面了,但是删除了 unpackage 还是不行
2025-09-16 14:20
DCloud_UNI_yuhe
回复 b***@163.com: 这个不是x的,是uniapp 的
2025-09-16 14:24