文件是从PhotoViewPicker中获取的 如何获取文件大小?
//更换头像
AppUtil.selectPhoto(1,(data: photoAccessHelper.PhotoSelectResult)=>{
let formData = new FormData()
let file = fs.openSync(data.photoUris[0], fs.OpenMode.READ_ONLY);
try {
let stat = fileIo.lstatSync(file.path);
} catch (e) {
Log.debug(e)
}
let buffer = new ArrayBuffer(4096);
let readLen = fs.readSync(file.fd, buffer);
console.info('readSync data to file succeed and buffer size is:' + readLen);
fs.closeSync(file);
返回后 调用 let stat = fileIo.lstatSync(file.path); 报错 没有找到文件
口味你好,你可以通过photoAccessHelper.getAssets接口获取对应uri的PhotoAsset对象。
这种方式获取的对象读取PhotoKeys.SIZE可以获取文件大小,具体可参考以下代码: