如题:HarmonyOS 请求报错如下 {"code":2300026,"message":"Failed to open/read local data from file/application"}?
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}); })
filePath需要转换为沙箱文件路径,文件操作转换参考:
https://developer.huawei.com/consumer/cn/doc/harmonyos-faqs/faqs-core-file-kit-0000001816452269
参考示例: