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 :
JavaScript
x
15
15
1
let fileTransfer = new FileTransfer();
2
url = encodeURI(url);
3
4
fileTransfer.download(
5
url,
6
cordova.file.externalApplicationStorageDirectory,
7
function(entry) {
8
console.log('download complete: ' + entry.toURL());
9
},
10
function(error) {
11
console.log('download error source ' + error.source);
12
console.log('download error target ' + error.target);
13
console.log('upload error code is ' + error.code);
14
});
15
Thanks
Advertisement
Answer
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) :
JavaScript
1
15
15
1
let fileTransfer = new FileTransfer();
2
url = encodeURI(url);
3
4
fileTransfer.download(
5
url,
6
cordova.file.externalApplicationStorageDirectory+'whatever.png',
7
function(entry) {
8
console.log('download complete: ' + entry.toURL());
9
},
10
function(error) {
11
console.log('download error source ' + error.source);
12
console.log('download error target ' + error.target);
13
console.log('upload error code is ' + error.code);
14
});
15