Corrupeted file when upload images using firebase storage in React Native

Viewed 126

I'm facing a weird problem using firebase storage, this is making me crazy, im trying to upload a QR imagen with no luck.

I tried two ways, expo-image-picker using the path that comes when an image is selected, and taking screen shots with react-native-view-shot using the returned path, but the result is always wrong, a file is successfully uploaded in both cases to the storage but it goes "corrupted", the size of the files is always 9B

enter image description here

If i try to open the image a message is display "The format file is not compatible"

enter image description here

My firebase application is based on WEB

I'm following the official documentation https://firebase.google.com/docs/storage/android/upload-files?hl=en

Here is the code

  uploadImage = async () => {
    var Transfer = 0;
    //const uri = this.state.selectedImage;
    const uri = URI.fromFilethis.state.selectedImage;
    const filename = uri.substring(uri.lastIndexOf('/') + 1);

    const uploadUri = Platform.OS === 'ios' ? uri.replace('file://', '') : uri;
    this.setState({isUploading:true});
    this.setState({isTransfering:0});

    var metadata = {
      name : 'imagen',
      contentType: 'image/jpge',
    };

      var storage = firebase.storage();
      var storageRef = storage.ref(filename);
      var putFile = storageRef.put(uploadUri);;

      putFile.on('state_changed', function(snapshot){
        var progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
        console.log('Upload is ' + progress + '% done');
        switch (snapshot.state) {
          case firebase.storage.TaskState.PAUSED: 
            console.log('Upload is paused');
            break;
          case firebase.storage.TaskState.RUNNING: 
            console.log('Upload is running');
            break;
        }
      }, function(error) {
      }, function() {

        putFile.snapshot.ref.getDownloadURL().then(function(downloadURL) {
          console.log('File available at', downloadURL);
        });
      });
    console.log(
      'Your photo has been uploaded to Firebase Cloud Storage!'
    );
  };

Here are my dependencies

enter image description here

Here is the resulting path of image picker

enter image description here

Result path of view shot

enter image description here

All image references comes from the root of the device, im not sure if that has something wrong, any one can help me please ?

0 Answers
Related