1

I'm trying to upload an Image to my firebase but I can't figure it out.

This is my code

_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);
}

I'm getting this error.

FirebaseStorageError {
 "code_": "storage/invalid-argument",
 "message_": "Firebase Storage: Invalid argument in `put` at index 0: Expected Blob or File.",
 "name_": "FirebaseError",
 "serverResponse_": null,
}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Millenial2020
  • 2,465
  • 9
  • 38
  • 83

2 Answers2

2

Use this code:

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

Instead of:

const blob = response.blob();

to solve your issue.

sɐunıɔןɐqɐp
  • 3,332
  • 15
  • 36
  • 40
0

try var ref= firebase.storage().ref().child('images/'+imageName) instead of yours