上传到存储设备时未捕获Firebase [对象对象]

问题描述 投票:3回答:1

[当我将图像作为Blob上载到Firebase Storage时,在Firefox和Chrome中出现未捕获的[对象对象]错误,但在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;
                });
firebase firebase-storage
1个回答
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');

© www.soinside.com 2019 - 2024. All rights reserved.