react-native firebase图像上传错误404

时间:2017-07-21 02:37:37

标签: javascript firebase react-native firebase-storage

我正在尝试使用firebase在react-native上创建图像上传功能。

这是我不断得到的错误:

FirebaseStorageError 
{
    "code_": "storage/unknown",
    "message_": "Firebase Storage: An unknown error occurred, please check the error payload for server response.", 
    "name_": "FirebaseError",
    "serverResponse_": "{\"error\": {\"code\": 404, \"message\": \"Not Found.  Could not access bucket [DEFAULT]\"}}",
}

这个错误是什么意思?我该如何解决?

编辑:

这是我的代码:

        return new Promise((resolve, reject) => {
        let uploadUri = Platform.OS === 'ios' ? uri.replace('file://', '') : 
        uri
        let uploadBlob = null
        let userImagePath = '0bWgZGQUSnf1wECGo2xi4O1sfWH2' + '/profile'; 
        let imageRef = firebase.storage().ref().child('images');

        fs.readFile(uploadUri, 'base64')
            .then((data) => {
                return Blob.build(data, { type: `${mime};BASE64` })
            })
            .then((blob) => {
                uploadBlob = blob
                return imageRef.put(blob, { contentType: mime })
            })
            .then(() => {
                uploadBlob.close()
                return imageRef.getDownloadURL()
            })
            .then((url) => {
                resolve(url)
            })
            .catch((error) => {
                console.log(error)
                reject(error)
            })
    })

我尝试将一个简单的字符串上传到firebase存储,但仍然遇到了同样的错误。

2 个答案:

答案 0 :(得分:0)

您应该首先在firebase中手动创建存储桶,然后在存储存储桶名称中输入相同的存储桶名称

答案 1 :(得分:0)

我在使用 web js 时遇到了类似的错误,所以我发现 url requisition post 是错误的:

https://firebasestorage.googleapis.com/v0/b/[Object object]/o?name=filename

https://firebasestorage.googleapis.com/v0/b/your_budget_nameHere/o?name=filename

所以为了解决我刚刚更新

<script src="https://www.gstatic.com/firebasejs/8.3.1/firebase-storage.js?v=1"></script>

<script src="https://www.gstatic.com/firebasejs/8.4.1/firebase-storage.js?v=1"></script>