admin管理员组文章数量:1355754
here im using ionic file transfer plugin for downloading a file and when ever i tried to download the file im getting below error
and also every time i build a file i need to add the below code in android also
public class FileProvider extends androidx.core.content.FileProvider
is there any other alternative for this download . i checked capacitor site but im not sure how to use file storage plugin in that and below is my code using file transfer
pdfUrl = '.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 plete: ' + entry.toURL());
this.saveData = entry.toURL();
}, (error) => {
// handle error
console.log(error);
});
here im using ionic file transfer plugin for downloading a file and when ever i tried to download the file im getting below error
and also every time i build a file i need to add the below code in android also
public class FileProvider extends androidx.core.content.FileProvider
is there any other alternative for this download . i checked capacitor site but im not sure how to use file storage plugin in that and below is my code using file transfer
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 plete: ' + entry.toURL());
this.saveData = entry.toURL();
}, (error) => {
// handle error
console.log(error);
});
Share
Improve this question
asked Jun 19, 2021 at 17:39
MadpopMadpop
7254 gold badges29 silver badges63 bronze badges
4 Answers
Reset to default 3On Android, cordova-plugin-file-transfer
requires cordova-plugin-whitelist
.
Install it with npm install cordova-plugin-whitelist
and then run npx cap update
Also, cordova-plugin-file-transfer
requires the path to the file where you want to write, you passed a directory, you should change fileTransfer.download(url, this.file.dataDirectory)
to fileTransfer.download(url, this.file.dataDirectory + '/NatureDeepReview.pdf')
try to the following :
firstly add the plugin: cordova-plugin-whitelist
secondely in the config.xml add the following <access origin="*" />
and the reference is used to answer the issue is :
https://github./ionic-team/capacitor/issues/1199
Check permission in your android manifest file and try again if your manifest file ok you added your permission then you have to check your destination route.
in your android manifest file
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
You probably need to create a whitelist - download the plugin via NPM
$ cordova plugin add cordova-plugin-whitelist
And add the following to config.xml
<access origin="*" subdomains="true" />
<allow-navigation href="http://*/*" />
<allow-navigation href="https://*/*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
本文标签: javascriptUnable to download file using ionic file transfer plugin in ionic 5Stack Overflow
版权声明:本文标题:javascript - Unable to download file using ionic file transfer plugin in ionic 5+ - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744037003a2579959.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论