DOMException: The requested file could not be read, typically due to permission problems that have occurred after a reference to a file was acquired

Viewed 5203

when i trying to read file using FileReader and the file size is 5.9gb and when this code run

var file = document.getElementById('uploadFileId').files[0];
   let reader = new FileReader();
   reader.onerror  = function() {
       console.log(reader.error);
   } 
   reader.onload = function(e) {
        console.log(" e.target.result ",e.target.result);
    }
    reader.readAsArrayBuffer(file);

then above error is generate in angularjs. here i want to achieve that multipart file want to divide in to 5mbs chunks and send to server.

3 Answers

I'm getting the same message, but only for files over 2GB. Seems as though there is a file size limit that triggers this unhelpful message.

This seems related to the Chrome 2GB ArrayBuffer size limit (other browsers have higher limits).
One solution is to upload the file chunks and then save them all to a file on the server:

const writableStream = new WritableStream({          
  start(controller) { },
  async write(chunk, controller) {
    console.log(chunk);
    // upload the chunks here
  },
  close() { },
  abort(reason) { },
});

const stream = e.target.files[0].stream();
stream.pipeTo(writableStream);

This can happen when the browser doesn't have access to shared folders etc.

Copying the file locally before uploading (e.g. to desktop) should solve the issue.

Related