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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.