HarmonyOS hash.hash()无法对从DocumentViewPicker获取的文件进行计算

代码如下:

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) => {
    Logger.info("calculate file hash succeed:", str);
  }).catch((err: BusinessError) => {
    Logger.error("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));
});
HarmonyOS
1天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
put_get

hash.hash() 仅支持沙箱路径,若使用系统公共目录文件,需将文件拷贝至沙箱目录下,沙箱路径:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/app-sandbox-directory-V5

hash参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-file-hash-V5

请参考代码:

let documentSelectOptions = new picker.DocumentSelectOptions();
let documentPicker = new picker.DocumentViewPicker();
documentPicker.select(documentSelectOptions).then((documentSelectResult: Array<string>) => {
  let file1 = fs.openSync(documentSelectResult[0])
  fs.copyFileSync(file1.fd, `data/storage/el2/base/files/${file1.name}`)
  let file2 = fs.openSync(`data/storage/el2/base/files/${file1.name}`, fs.OpenMode.READ_WRITE)
  console.log(`file fd ==> ${file2.fd} | file path ==> ${file2.path}`)
  hash.hash(file2.path, "sha256").then((str: string) => {
    console.info("calculate file hash succeed:", str);
  }).catch((err: BusinessError) => {
    console.error("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));
});
分享
微博
QQ
微信
回复
1天前
相关问题
HarmonyOS 文件Hash处理
86浏览 • 1回复 待解决
HarmonyOS Hash方法
46浏览 • 1回复 待解决
如何获取应用签名证书hash
1863浏览 • 1回复 待解决
如何获取对象唯一标识(Hash值)
604浏览 • 1回复 待解决
OceanBase哈希(HASH)分区是什么?
4130浏览 • 1回复 待解决
redis中Hash操作是什么?
2829浏览 • 1回复 待解决
HarmonyOS 每次sync,libak.sohash都会变
123浏览 • 1回复 待解决
InnoDB为什么需要自适应Hash索引?
2419浏览 • 1回复 待解决
TairHash相较于Redis Hash提升有哪些?
3241浏览 • 1回复 待解决
Redis数据类型散列hash是什么?
2693浏览 • 1回复 待解决