FileTransfer Plugin do not work on browser


#1

Hi everyone,

I am trying to download a file with the FileTransfer native plugin in a desktop browser and mobile browser, but I get this error in both platforms (Browser/Android Chrome):

body:null
code:1
exception:null
http_status:null
source:"./assets/docs/Contrat_base.pdf"
target:"filesystem:file:///persistent/contrat.pdf"

I am running the ionic cordova run browser command to test this part of the application.

Here is the code:

let url = './assets/docs/Contrat_base.pdf'; // It can be a S3 bucket link

const fileTransfer: FileTransferObject = this.transfer.create();

fileTransfer.download(url, this._file.dataDirectory + "/contrat.pdf", true, {
   fileName: "contrat.pdf"
}).then((entry) => {
   console.log('download complete: ' + entry.toURL());
}, (error) => {
   console.log("ERROR:", error);
 });

How can I download the file? Do I need different methods for each type of platform?

Please help me!

Thanks in advance!


#2

This blog post would be of interest to you: Transition off of cordova-plugin-file-transfer


#3

Any news on that?

I have the same problem, the File transfer plugins works on android but not on the browser platform.

The example they give in your link is wrong in many ways :

1. window.requestFileSystem

window.requestFileSystem is not standard (https://developer.mozilla.org/en-US/docs/Web/API/Window/requestFileSystem) so it’s highly discouraged to use in production code by the mdn…

2. The code contains errors

LocalFileSystem.PERSISTENT should be replaced by window.PERSISTENT as documented on the page I linked above.

var reader = new FileReader();
reader.addEventListener("loadend", function() {
     [...]
});

is invalid too, it should be:

var reader = new FileReader();
reader.onload = function(event) {
    [...]
};

as documented here: https://developer.mozilla.org/en-US/docs/Web/API/FileReader/onload

So for me this solution is really unsatisfying, is there any alternative?