当我将图像作为blob上传到Firebase存储时,我在Firefox和Chrome中收到了一个未捕获的[object Object]错误,但在Edge中却没有。当我使用下面从Firebase网站提取的代码示例时,我收到了错误消息。说国家正在运行,进展是0%。 它在昨晚工作,任何更改都已恢复为工作版本。
var uploadImg = storage.ref().child('images/' + user.uid + '/savedProducts/blah').put(savedImg);
uploadImg.on(firebase.storage.TaskEvent.STATE_CHANGED, // or 'state_changed'
function(snapshot) {
// Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded
var progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
console.log('Upload is ' + progress + '% done');
switch (snapshot.state) {
case firebase.storage.TaskState.PAUSED: // or 'paused'
console.log('Upload is paused');
break;
case firebase.storage.TaskState.RUNNING: // or 'running'
console.log('Upload is running');
break;
}
},
function (error) {
switch (error.code) {
case 'storage/unauthorized':
// User doesn't have permission to access the object
break;
case 'storage/canceled':
// User canceled the upload
break;
case 'storage/unknown':
// Unknown error occurred, inspect error.serverResponse
break;
}
},
function () {
// Upload completed successfully, now we can get the download URL
var downloadURL = uploadTask.snapshot.downloadURL;
});
答案 0 :(得分:0)
这是一个较晚的答案,但仍然如此。我希望这可以帮助人们。
当您尝试将Blob上传到存储时,您使用了方法
storage.ref().child('images/' + user.uid + '/savedProducts/blah').put(savedImg);
在我的情况下,为了将Blob放入Firebase存储中,我需要使用方法putString(saveImage, 'data_url')
。 'data_url
是格式。
完整代码
storage.ref().child('images/' + user.uid + '/savedProducts/blah').putString(saveImage, 'data_url');