简体   繁体   中英

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... 在此输入图像描述

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM