Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
31
rated 0 times [  32] [ 1]  / answers: 1 / hits: 16624  / 8 Years ago, tue, may 31, 2016, 12:00:00

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


More From » android

 Answers
176

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);
});

[#61945] Monday, May 30, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
parisc

Total Points: 438
Total Questions: 119
Total Answers: 119

Location: Turkmenistan
Member since Sat, Apr 16, 2022
2 Years ago
;