HarmonyOS 使用DocumentViewPicker获取到的文件后用hash.hash失败?

let documentSelectOptions = new picker.DocumentSelectOptions();
let documentPicker = new picker.DocumentViewPicker();
documentPicker.select(documentSelectOptions).then((documentSelectResult: Array<string>) => {
  let filePath = documentSelectResult[0];
  hash.hash(filePath, "sha256").then((str: string) => {
    hilog.info(0x0000, 'testTag', "calculate file hash succeed:", str);
  }).catch((err: BusinessError) => {
    hilog.error(0x0000, 'testTag', "calculate file hash failed with error",
      " message: " + err.message + ", error code: " + err.code);
  });
}).catch((err: BusinessError) => {
  console.error('DocumentViewPicker.select failed with err: ' + JSON.stringify(err));
});

报错为:13900002;根据文档描述使用该功能模块对文件/目录进行操作前,需要先获取其应用沙箱路径,但是documentSelectResult已经是绝对路径了,该如何处理?

阅读 570
1 个回答

hash接口只支持Path作为入参。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进