Answer the question
In order to leave comments, you need to log in
Cordova + FileTransfer - how to download a file from a server to a mobile device?
Good day everyone!
I'm using: Cordova 5.1.1 + FileTransfer plugin
I'm trying to upload a file (JPG image) from a remote server to the phone's memory. The code below works, it does not return an error, but it does not load the file either. What could be the problem? Searched all over the internet but didn't find a solution.
// URL картинки
var assetURL = encodeURI( "http://mysite.com/somefile.jpg" );
// имя файла, которое мы ему присвоим
var fileName = "gamebackground.jpg";
// получаем путь каталога для файлов приложения
var store = cordova.file.dataDirectory;
// проверяем наличие файла в папке. Если нет, запускаем download
window.resolveLocalFileSystemURL( store + fileName, onSuccess, download );
function onSuccess() {
alert( "Already downloaded!" );
}
function download() {
var fileTransfer = new FileTransfer();
fileTransfer.download( assetURL, store + fileName, function( entry ) {
alert( "Download complete!" );
}, function( err ) {
alert( "Error "+ err );
} );
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question