Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Storage invalid argument on upload

I keep getting an Invalid argument in put at index 0: Expected Blob or File error. The funny thing is the argument is totally a file...

Here is the code:

var file = document.getElementById('cke_69_fileInput')
          .contentWindow.document.getElementById('cke_69_fileInput_input').files[0];

var storageUrl = 'noticias/imagenes/';
var storageRef = firebase.storage().ref(storageUrl + file.name);
console.warn(file); // Watch Screenshot
var uploadTask = storageRef.put(file);

Here's the screenshot of the actual file warn just before the error asking for a file... enter image description here

like image 974
cerealex Avatar asked Aug 20 '16 18:08

cerealex


1 Answers

try converting file to blob...

  var reader = new FileReader();
  reader.onloadend = function (evt) {
    var blob = new Blob([evt.target.result], { type: "image/jpeg" });

    var storageUrl = 'noticias/imagenes/';
    var storageRef = firebase.storage().ref(storageUrl + file.name);
    console.warn(file); // Watch Screenshot
    var uploadTask = storageRef.put(blob);

  }

  reader.onerror = function (e) {
      console.log("Failed file read: " + e.toString());
  };
  reader.readAsArrayBuffer(file);
like image 188
Aaron Saunders Avatar answered Oct 19 '22 17:10

Aaron Saunders