4

I am facing a issue whereby my android users are unable to upload video files from their google drive to the website (when will upload file via input tag, you get the option to retrieve the file from google drive). What i found out so far is that if i send a partial files into readAsArrayBuffer (FileReader API) it wont work, it will only work if i use the whole file.

The reason i am passing a partial files is to handle the case of latency issue. I am using AngularJS. I am unable to share the code as its against my company policy.

UPDATE: Ytd, i ran FileReader.onerror it return this error:

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

I am able to upload the files on Firefox and not Chrome.

Thank you

$scope.rewriteVideoFile = function(file, out) {
    var totalBytes = 1750000;
    return new Promise(function(resolve, reject) {
      var reader = new FileReader();
      reader.onload = function() {
        //Logic here
      }

      reader.readAsArrayBuffer(file.slice(0, totalBytes));
      // reader.readAsArrayBuffer(file); this will work
    });
};

function createVideoBlob(file) {
  var maxSize = 1550000;
  var sendSize = Math.min(maxSize, file.size);
  return new Promise(function(resolve, reject) {
    if (file.size <= maxSize) {
      return resolve(file);
    } else if (file.type === 'video/quicktime' || file.type === 'video/mp4') {
      var out = [];
      scope.rewriteVideoFile(file, out).then(function () {
      console.log('rewriteVideoFile .then');
      var blob = new Blob(out, {type : 'application/octet-stream'});
      return resolve(blob);
      });
    } else {
       return resolve(file.slice(0, sendSize, 'application/octet-stream'));
    }
  })
}
georgeawg
  • 48,608
  • 13
  • 72
  • 95
kianncja
  • 51
  • 2
  • I have added the code, thank you – kianncja Jul 26 '18 at 17:33
  • ES6 promises are not integrated with the AngularJS execution context. Only operations which are applied in the AngularJS execution context will benefit from AngularJS data-binding, exception handling, property watching, etc. – georgeawg Jul 26 '18 at 21:28
  • [From Review](https://stackoverflow.com/review/reopen/20416904) - There is no need to use `new Promise` to manufacture a new promise from a `.then` block because the `.then` method already returns a promise. Doing so is considered an [anti-pattern](https://stackoverflow.com/questions/30750207/is-this-a-deferred-antipattern) [1](http://plnkr.co/edit/Up1X5SRqnNFzG5u8KtMj?p=preview). – georgeawg Jul 26 '18 at 22:08

0 Answers0