我在尝试上传到firebase时在控制台中收到下一个错误:
Uncaught FirebaseError: Firebase Storage: Invalid argument in `put` at index 0: Expected Blob or File.
JS:
var file, fileName, fileRef, storageImagesRef, storageRef, uploadTask;
var storageFolder = '/pictures/';
function getFileName(fileInput) {
file = fileInput.files;
fileName = file[0].name;
storageRef = firebase.storage().ref(storageFolder + fileName);
uploadTask = storageRef.put(file);
};
HTML
<input type="file" onchange="getFileName(this)" accept=".png, .jpg, .bmp, .JPEG, .JPG, .svg, .tiff, .gif">
我做错了什么?
答案 0 :(得分:3)
问题是由于代码中使用了file
变量的方式。变量被赋予FileList
- 这是您传递给put
的内容。如果您为其分配了File
:
function getFileName(fileInput) {
file = fileInput.files[0];
fileName = file.name;
storageRef = firebase.storage().ref(storageFolder + fileName);
uploadTask = storageRef.put(file);
};