I am updating the application from the telephone plug 2. * to cordova 3.4 Now everything is working fine, only downloading files does not work.
I need to download a file from the Internet (edited by the host) and save it as a JSON file so that the content can be processed later. The download works fine, the file will be displayed on the file system, but FileReader does not fire an event onloadend.
I tried a few things like the events onprogressor onerror, as file.toURIand FileReader.readAsDataURL- nothing worked. Anyone any ideas?
Notes:
app.log can be considered as an alias for console.logprint_r defined in another file, works great- The downloaded file is only a few kilobytes, it should not be a performance problem
- Work on iOS equipment
Full code (extracted and abbreviated):
var fileTransfer = new FileTransfer();
var loadingStatus = 0;
fileTransfer.onprogress = function (progressEvent) {
if (progressEvent.lengthComputable) {
loadingStatus = Math.floor(progressEvent.loaded / progressEvent.total * 100);
} else {
loadingStatus++;
}
app.log('Transfer Progress: ' + loadingStatus);
};
fileTransfer.download(
encodeURI('http://www.example.com/export'),
'cdvfile://localhost/persistent/import.json',
function (file) {
var FileReader = new FileReader();
FileReader.onloadend = function (evt) {
app.log('Filereader onloadend');
app.log(evt);
};
FileReader.readAsText(file);
},
function (error) {
app.log("FileTransfer Error: " + print_r(error));
}
);
source
share