1
votes

I am trying to upload image to firebase storage or firestore and i am getting the following error:

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

how can I resolve this?

I know I have to convert the image to file or blob format,

but how can I do this, in this case??

PS: I am NOT using EXPO

below is my function that takes the image

const handleSelectPicture = useCallback(() => {
    ImagePicker.showImagePicker(
      {
        noData: true,
        title: 'Selecione a foto desejada',
        cancelButtonTitle: 'Cancelar',
        takePhotoButtonTitle: 'Usar câmera',
        maxWidth: 800,
        maxHeight: 800,
        chooseFromLibraryButtonTitle: 'Escolher da galeria',
      },
      response => {
        if (response.didCancel) {
          return;
        }

        if (response.error) {
          Alert.alert('Erro ao fazer upload da foto, tente novamente.');
          return;
        }

        console.log('image: >>>> ', response.uri);

        setImageURI({ uri: response.uri });

        console.log('State uri>>>>', imageURI);
      },
    );
  }, [imageURI]);

below is how I Am trying to upload that image to firebase:

    await firebase
          .auth()
          .createUserWithEmailAndPassword(
            email,
            password,
          )
          .then(async auth => {
            console.log('valueee', auth);

            await db
              .collection('users')
              .doc('userData')
              .set({

                photo: imageURI,
                document: params.fileSelected,
                address: [data],
              });

            firebase
              .storage()
              .ref(`users/${auth.user.uid}/profileImage.jpg`)
              .put(imageURI.uri)
              .then(() => {
                setUser(auth);
              });
          })
1

1 Answers

0
votes

The error message:

Invalid argument in put at index 0: Expected Blob or File.

Is telling you that you passed an invalid value to put(). If you're hoping to pass a URL to some other file to upload, that won't work. You can only upload content that exists locally on the machine running the code.

If you want to transfer the contents of another URL, you won't be able to do that with the web client SDK. You will have to write some backend code to download the content from the URL, then upload it to Cloud Storage.