[IONIC 4] Others methods to download files

Hi can you please help me i am using capacitor in my project with ionic 5 and i am getting error code 3 while downloading

The file transfer plugin was sunsetted years ago; just use HttpClient to download files.

2 Likes

Hii @leonardofmed

I am downloading using this code in Android:

 let uri = encodeURI("https://www.learningcontainer.com/wp-content/uploads/2020/09/Sample-Image-File-for-Testing.png?ezimgfmt=ng:webp/ngcb4");
    const fileTransfer: FileTransferObject = this.transfer.create();
    fileTransfer.download(uri, this.file.dataDirectory + "sample.jpg").then((entry) => {
      console.log(entry);
    })
    .catch((e) =>{
      console.log(e);
    });

But i am getting this Error

FileTransferError

  1. body: null
  2. code: 3
  3. exception: null
  4. http_status: 401
  5. source: "https://www.learningcontainer.com/wp-content/uploads/2020/09/Sample-Image-File-for-Testing.png?ezimgfmt=ng:webp/ngcb4"
  6. target: "file:///data/user/0/com.maximl.demoapp/files/sample.jpg"
  7. __proto__: Object

I have given all the permission’s.
Same code is working fine in iOS

You are receiving an error 401 from server, which means you are not authorized to access it. However, as the message before yours says, FileTransfer is no longer supported or recommended, the ideal is to replace the method with HttpClient from Angular.

Hii @leonardofmed ,
This plugin is not used for Android Downloading.
But still i can use this plugin for iOS

Can I download files like pdf,mp3 using URL of the same in Android externalRootDirectory folder using HttpClient ?
Can you please share any example of the same to download it in Android device using url?

Can you please share any example ?