1、首先将下载好的文件,保存到本地目录,这个目录是用户看不到的;
2、然后通过picker的save保存文件,这个picker,它只是获取公共目录uri用的
3、当picker有回调时,将公共目录的uri获取之后,把下载好的文件复制到公共路径下,
公共路径=uris1[0]+'/'+'56151651.pdf'
- async saveSystemFile(name:string,path:string){
- try {
- let documentSaveOptions = new picker.DocumentSaveOptions();
- documentSaveOptions.pickerMode=picker.DocumentPickerMode.DOWNLOAD
- documentSaveOptions.fileSuffixChoices = ['文档|.txt', '.pdf'];
- documentSaveOptions.newFileNames = [name];
- let documentPicker = new picker.DocumentViewPicker(getContext() as common.Context);
- documentPicker.save(documentSaveOptions).then((uris1: Array<string>) => {
- let uri = uris1[0]+'/'+name;
- let srcDirUriLocal: string = fileUri.getUriFromPath(path);
- fs.copy(srcDirUriLocal, uri, (err: BusinessError) => {
- if (err) {
- console.error(`Failed to copy: ${JSON.stringify(err)}`);
- return;
- }
- })
- }).catch((err: BusinessError) => {
- console.error('DocumentViewPicker.save failed with err: ' + JSON.stringify(err));
- });
- } catch (error) {
- let err: BusinessError = error as BusinessError;
- console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err));
- }
- }
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |