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 complete: ' + entry.toURL());
this.saveData = entry.toURL();
}, (error) => {
// handle error
console.log(error);
});
Shortcut to the steps:Create New Ionic 3 and Cordova App. Install and Configure Camera, File and File Transfer Plugin. Create Upload Page and Controller. Test Upload Image File using Android and iOS Device.
On 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.com/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" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With