const chooseFile = (params: ESObject): Promise<ESObject> => {
return new Promise((resolve, reject) => {
const documentSelectOptions = new picker.DocumentSelectOptions()
documentSelectOptions.maxSelectNumber = 0;
const documentViewPicker = new picker.DocumentViewPicker();
documentViewPicker.select(documentSelectOptions).then((documentSelectResult: Array<string>) => {
const uri: string = documentSelectResult[0];
const fileName = getFileName(uri);
const fileType = fileName.lastIndexOf('.') > -1 ? fileName.substring(fileName.lastIndexOf('.')) : '';
const localId = `${dayjs().format('YYYYMMDDHHmmssSSS')}_${Global.getInstance().getPartIMEI()}${fileType}`;
const saveDir = `${SYSTEM_DIRECTORY_DMTMP}files/`;
const dest = `${saveDir}${localId}`;
if (!isFileExist(saveDir)) {
fs.mkdirSync(saveDir, true);
}
// 拷贝文件到临时目录
fs.copyFileSync(uri, dest);
resolve({
localId: localId,
fileName: fileName,
fileType: fileType,
localPath: dest,
fileSize: getFileSize(dest)
});
}).catch((err: BusinessError) => {
reject(err);
})
})
}
通过documentViewPicker.select选择的文件调用fs.copyFileSync报错
需要检查一下文件路径是否正确
fs.copyFileSync示例参考