0

I'm trying to download a ZIP file to use within my app.

However, when the file is larger than 50 megabytes, the download fails. Does anyone know how I can increase this 50 megabyte limit?

My code is:

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(); 
3
  • Most likely your app is trying to load the whole file into memory instead of processing it step-by-step. Commented Apr 23 at 16:16
  • And is there a way to do this step by step? Commented Apr 24 at 10:54
  • This question is similar to: CORDOVA: I can DOWNLOAD 30 MB, but not 60 MB ? (cordova-plugin-file). If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Apr 30 at 7:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.