在这里我使用 ionic 文件传输插件下载文件,当我尝试下载文件时,我得到以下错误
而且每次我构建一个文件时,我还需要在 android 中添加以下代码
public class FileProvider extends androidx.core.content.FileProvider
这个下载还有其他选择吗?我检查了电容器站点,但我不确定如何在其中使用文件存储插件,下面是我使用文件传输的代码 pdfUrl = 'https://www.cs.toronto.edu/~hinton/absps/NatureDeepReview.pdf';
constructor(private transfer: FileTransfer, private file: File) {}
download() {
const fileTransfer: FileTransferObject = this.transfer.create();
const url = this.pdfUrl;
fileTransfer.download(url, this.file.dataDirectory).then((entry) => {
console.log('download complete: ' + entry.toURL());
this.saveData = entry.toURL();
}, (error) => {
// handle error
console.log(error);
});
最佳答案
在 Android 上,cordova-plugin-file-transfer
需要 cordova-plugin-whitelist
.
使用 npm install cordova-plugin-whitelist
安装它然后运行 npx cap update
另外,cordova-plugin-file-transfer
需要您要写入的文件的路径,您传递了一个目录,您应该更改fileTransfer.download(url, this.file.dataDirectory)
至fileTransfer.download(url, this.file.dataDirectory + '/NatureDeepReview.pdf')
关于javascript - 无法在 ionic 5+ 中使用 ionic 文件传输插件下载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68049352/