Я пытаюсь загрузить zip -файл для использования в моем приложении.var var_url = 'https://example.com/teste.zip'; // Location of the file to be downloaded
var fileURL = "///storage/emulated/0/Android/data/myapp/teste.zip"; // Save in this folder
var req = new XMLHttpRequest();
req.open("GET", var_url, true);
req.responseType = "blob";
req.onload = function (event) {
var blob = req.response;
alert(blob.size);
alert(blob.type);
alert("WORKS!");
alert(fileURL);
alert(var_url);
if (blob.size>52747758) { alert('This file is over 50 megabytes') } //52747758 or 50.30 megas
// cordova.file.etc is where you will save the file. In this case, inside the app folder, in the main storage in Android
window.resolveLocalFileSystemURL(cordova.file.externalApplicationStorageDirectory, function (directoryEntry) {
// the 'temp.pdf' is the name you want for your file.
directoryEntry.getFile('teste.zip', { create: true }, function (fileEntry) {
fileEntry.createWriter(function (fileWriter) {
fileWriter.onwriteend = function (e) {
// great success!
alert('Write of file completed.');
};
fileWriter.onerror = function (e) {
// Meh - fail
alert('Write failed');
};
fileWriter.write(blob);
} );
} );
});
};
req.send();
Подробнее здесь: https://stackoverflow.com/questions/795 ... nload-file
Cordova Android -файл скачать файл ⇐ Android
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Ошибка Cordova при создании проекта Android с помощью команды Cordova build Android
Anonymous » » в форуме Android - 0 Ответы
- 33 Просмотры
-
Последнее сообщение Anonymous
-