react-native-firestack: filepath.replace is not a function

I got “filepath.replace is not a function” when I try to upload some picture to firebase storage.

`
const firestack = new Firestack();

    firestack.storage.setStorageUrl('chatapp-e4bc6.appspot.com');
    firestack.storage.uploadFile('photos/1.jpg', source, {
      contentType: 'image/jpeg',
      contentEncoding: 'base64',
    })
    .then((res) => console.log('The file has been uploaded'))
    .catch(err => console.error('There was an error uploading the file', err))`

Running on Android Emulator.

err

update: The problem is in “storage.js” line 85:

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 2
  • Comments: 15 (1 by maintainers)

Most upvoted comments

I think I found the solution… If you are using react-native-firebase, you don’t need to create a blob file. Just pass the path of the picture to .put method. imageRef.put(uri, { contentType: mime }); It seems react-native-firebase takes care of all else.

Same error here, any suggestions?

Edit: return imageRef.put(blob._ref, { contentType: mime });

Fixed it for me, but files are getting uploaded without file extension, any ideas?

Before I used rn-fetch-blob with ‘firebase’ (the npm package), when I use react-native-firebase, no need this lib (rn-fetch-blob) anymore. imageRef.put(uri,... like @perrosnk mentioned is a good answer for the issue.

@justfede I have a similar issue, but I couldn’t get it solved. You could check the code below.

  import RNFirebase from 'react-native-firebase';
  import RNFetchBlob from 'react-native-fetch-blob';
  
  // Prepare Blob support
  const Blob = RNFetchBlob.polyfill.Blob;
  const fs = RNFetchBlob.fs;
  
  export const firebaseApp = RNFirebase.initializeApp(configurationOptions);
  
  ...
  
  let uploadBlob = null;
  const imageRef = firebaseApp.storage().ref('/photos/`).child('image');

  fs.readFile(uploadUri, 'base64')
    .then((data) => {
      return Blob.build(data, { type: `${mime};BASE64` });
    })
    .then((blob) => {
      uploadBlob = blob;
      return imageRef.put(blob, { contentType: mime });
    })
    .then(() => {
      uploadBlob.close();
      return imageRef.getDownloadURL();
    })
    .then((url) => {
      //Success
      console.log('success');
    })
    .catch((error) => {
      console.log('failed on uploading image:', error);
  })
  ...

I get this error. { [TypeError: undefined is not a function (evaluating ‘filePath.replace(‘file://’, ‘’)’)]

Can you please help me?

@perrosnk Thanks I spent whole day for this error But now it works for me

very very thanks