HarmonyOS 使用picker打开文件选择器选择文件完成后如何获取到文件大小

如果我选择的不是图片视频而是word之类的怎么获取到文件大小

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

在拿到uri后调用file接口获取文件大小,详情见:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/photoaccesshelper-photoviewpicker-V5#指定uri读取文件数据

let uris: Array<string> = [];
const photoViewPicker = new photoAccessHelper.PhotoViewPicker();
photoViewPicker.select(photoSelectOptions).then((photoSelectResult: photoAccessHelper.PhotoSelectResult) => {
  uris = photoSelectResult.photoUris;
  console.info('photoViewPicker.select to file succeed and uris are:' + uris);
  let uri: string = '';
  let file = fileIo.openSync(uri, fileIo.OpenMode.READ_ONLY);
  console.info('file fd: ' + file.fd);
  let buffer = new ArrayBuffer(4096);
  let readLen = fileIo.readSync(file.fd, buffer);
  console.info('readSync data to file succeed and buffer size is:' + readLen);
}).catch((err: BusinessError) => {
  console.error(`Invoke photoViewPicker.select failed, code is ${err.code}, message is ${err.message}`);
})
分享
微博
QQ
微信
回复
3天前
相关问题
如何打开指定文件夹,选择文件返回
8752浏览 • 1回复 待解决
HarmonyOS picker选择器的数据源问题
16浏览 • 1回复 待解决
HarmonyOS 图片选择器怎么实现
83浏览 • 1回复 待解决