I have a problem on cordova (android), when I try to download a file (a .zip exactly), It always occured a error code 1. The url downloads well on my computer. Here is the code :
let fileTransfer = new FileTransfer();
url = encodeURI(url);
fileTransfer.download(
url,
cordova.file.externalApplicationStorageDirectory,
function(entry) {
console.log('download complete: ' + entry.toURL());
},
function(error) {
console.log('download error source ' + error.source);
console.log('download error target ' + error.target);
console.log('upload error code is ' + error.code);
});
Thanks
The error was that I forgot to specify the name of the file when it will be downloaded on the device, I didn't know I had to specify that. So here is the corrected code (modifications at lign 6) :
let fileTransfer = new FileTransfer();
url = encodeURI(url);
fileTransfer.download(
url,
cordova.file.externalApplicationStorageDirectory+'whatever.png',
function(entry) {
console.log('download complete: ' + entry.toURL());
},
function(error) {
console.log('download error source ' + error.source);
console.log('download error target ' + error.target);
console.log('upload error code is ' + error.code);
});
Code 1 corresponds to FileTransferError.FILE_NOT_FOUND_ERR
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