I am trying to use react-native-camera to take a photo then upload that photo to Firebase storage. I am able to retrieve the file as a blob using RNFetchBlob, however when trying to .put() into Firebase Storage, I get a
Firebase Storage: Invalid argument in
put
at index 0: Expected Blob or File.
I also tried to use .putString()
and pass it in as a base64 string, or just the uri however I get similar issues. Here is some related code.
export function createPhoto(photo: TakePictureResponse): Boolean { var ref = storage.ref(); var photoRef = ref.child('photos'); if (Platform.OS === 'ios') { var filePath = photo.uri.replace('file:', ''); } else { filePath = photo.uri.split('raw%3A')[1].replace(/\%2F/gm, '/'); } RNFetchBlob.fs.readFile(filePath, 'base64').then((data) => { photoRef.put(data).then((snapshot) => { console.log('Uploaded a photo'); console.log(snapshot.downloadURL); }); });
Update: RNFetchBlob.fs.readFile() returns a string depending on the decoder option you pick (for this example it is base64). However I still have issues as Firebase Storage will not accept my base64 string with .putString(data, 'base64'). I get a "Firebase Storage: String does not match format 'base64': Invalid character found"
error.