React Native Expo如何使用Expo Image Picker将图像上传到Firebase

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

我正在尝试将图像上传到我的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个回答
1
投票

尝试用var ref= firebase.storage().ref().child('images/'+imageName)代替您的

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