【问题标题】:React Native Expo How to upload an image to Firebase using expo Image pickerReact Native Expo 如何使用 expo 图像选择器将图像上传到 Firebase
【发布时间】:2020-04-23 00:08:29
【问题描述】:

我正在尝试将图像上传到我的 Firebase,但我无法弄清楚。

这是我的代码

_pickImage = async () => {
    let result = await ImagePicker.launchImageLibraryAsync({
        mediaTypes: ImagePicker.MediaTypeOptions.All,
        allowsEditing: true,
        aspect: [4, 3],
        quality: 1
    });

    if (!result.cancelled) {
        this.uploadImage(result.uri, 'test-image')
            .then(() => {
                console.log('it work')
            })
            .catch(error => {
                console.log('it does not work')
                console.error(error)
            })
    }
};

uploadImage = async (uri, imageName) => {
    const response = await fetch(uri);
    const blob = response.blob();

    const ref = firebase.storage().ref().child(`images/${imageName}`);
    return ref.put(blob);
}

我收到了这个错误。

FirebaseStorageError {
 "code_": "storage/invalid-argument",
 "message_": "Firebase Storage: Invalid argument in `put` at index 0: Expected Blob or File.",
 "name_": "FirebaseError",
 "serverResponse_": null,
}

【问题讨论】:

    标签: javascript react-native expo firebase-storage react-native-image-picker


    【解决方案1】:

    使用此代码:

    `const blob = await response.blob();`
    

    代替:

    const blob = response.blob();

    解决您的问题。

    【讨论】:

      【解决方案2】:

      试试var ref= firebase.storage().ref().child('images/'+imageName),而不是你的

      【讨论】:

        猜你喜欢
        • 2021-06-07
        • 1970-01-01
        • 2020-06-30
        • 1970-01-01
        • 1970-01-01
        • 2023-01-31
        • 2021-01-24
        • 2021-05-14
        • 1970-01-01
        相关资源
        最近更新 更多