HarmonyOS 请求报错如下 {"code":2300026,"message":"Failed to open/read local data from file/application"}

HarmonyOS
3天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
zxjiu

filePath需要转换为沙箱文件路径,文件操作转换参考:

https://developer.huawei.com/consumer/cn/doc/harmonyos-faqs/faqs-core-file-kit-0000001816452269

参考示例:

let uris: Array<string> = [];
const photoViewPicker = new picker.PhotoViewPicker();
const photoSelectOptions = new picker.PhotoSelectOptions();
photoSelectOptions.maxSelectNumber = 1; // 选择媒体文件的最大数目
photoViewPicker.select(photoSelectOptions).then((photoSelectResult: picker.PhotoSelectResult) => {
  uris = photoSelectResult.photoUris;
  console.info(‘photoViewPicker.select to file succeed and uris are:’ + uris);
  let file = fs.openSync(uris[0], fs.OpenMode.READ_ONLY);

  let file2 = fs.openSync(this.filesDir + ‘/test.jpg’, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);//先创建有读写权限的文件,再把不可读写的文件复制过来
  fs.copyFileSync(file.fd, file2.fd);
  // 关闭文件
  fs.closeSync(file);
  fs.closeSync(file2);

}).catch((err: BusinessError) => {
  console.error(Invoke photoViewPicker.select failed, code is ${err.code}, message is ${err.message});
})
分享
微博
QQ
微信
回复
3天前
相关问题
HarmonyOS /data/local/tmp路径uri获取
36浏览 • 1回复 待解决
open_file插件适配HarmonyOS需求
314浏览 • 1回复 待解决