javascript - 无法在离子 5+ 中使用离子文件传输插件下载文件
问题描述
在这里我使用离子文件传输插件下载文件,当我尝试下载文件时,我得到以下错误
而且每次我构建一个文件时,我还需要在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')
推荐阅读
- reactjs - 未处理的拒绝 (TypeError)
- events - 缺少 GA4 事件参数
- spring-webflux - 如何将 Flux-Results 放入一组 Mono-Bean
- java - Java Streams 在 Codility 上的性能为 0%
- python - Flask 应用程序的启动应该如何构建?
- pandas - 在 for 循环中根据名称复制/分配 Pandas 数据框
- dependency-injection - ServiceStack:container.AutoWire(this) 给出 NullReferenceException
- amazon-web-services - 使用 IAM 角色的 cfInvalidate (jenkinsci / pipeline-aws-plugin)
- android - 从科尔多瓦的 playstore 获取应用程序版本
- mongodb - 获取“信号 15(终止),将在当前 cmd 结束后终止”和 Mongodb 关闭?配置中没有提到分叉条件