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
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
Share Improve this question asked May 31, 2016 at 16:12 Basile BeldameBasile Beldame 4301 gold badge4 silver badges16 bronze badges 3- 1 Error code as per plugin documentation is "NOT_FOUND_ERR" which means the requested resource is not found. Ensure the resource is available and also ensure you have added Cordova whitelist plugin to make CORS request – Gandhi Commented May 31, 2016 at 17:03
- It wasn't the problem, but thank you for taking time to help me – Basile Beldame Commented May 31, 2016 at 19:04
- Glad it worked. Looks like not found error meant file not found in device to write I guess. – Gandhi Commented May 31, 2016 at 19:07
2 Answers
Reset to default 19The 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);
});
- Make sure path of target file ( downloaded file ) is valid.
- Make sure target file name is valid.
- Make sure download file path is valid.
Code 1 corresponds to FileTransferError.FILE_NOT_FOUND_ERR