davideast / firebase-react-native-sample

Using React Native with Firebase
786 stars 135 forks source link

File Storage Doesn't Work w/React Native #5

Closed aaronksaunders closed 8 years ago

aaronksaunders commented 8 years ago

I believe this is an issue in React-Native's implementation of the binary upload, but I will start here since I am getting an error message back

error {"code":"storage/unknown","message":"Firebase Storage: An unknown error occurred, please check the error payload for server response.","serverResponse":"Multipart body does not contain 2 or 3 parts.","name":"FirebaseError"}

Code

var fileRef = firebase.storage().ref('images/sample-text')
var uploadTask = fileRef.put(new File(['this is a small amount of data'], 'sample-text.txt', { type: "text/plain" }), { type: "text/plain" });

uploadTask.on('state_changed', function (snapshot) {
    console.log('state_changed', snapshot);
}, function (error) {
    console.log("error", JSON.stringify(error));
}, function () {
    // Handle successful uploads on complete
    // For instance, get the download URL: https://firebasestorage.googleapis.com/...
    var downloadURL = uploadTask.snapshot.downloadURL;
})

I see the same issue on IOS/Android... goes into the Firebase source and then it is over...

BTW the code works in regular reactJS

See here... https://jsfiddle.net/Aaronksaunders/69z2wepo/48545/

davideast commented 8 years ago

Hey @aaronksaunders,

This unfortunately is a known limitation of Firebase Storage.

React Native operates in a Node.js environment and Firebase Storage only supports File and Blob types which are browser dependent.

Check the blog post for more info: https://firebase.googleblog.com/2016/07/firebase-react-native.html

yaronlevi commented 7 years ago

+1 It is really unfortunate that Firebase on React Native dose not support uploads.

aaronksaunders commented 7 years ago

@yaronlevi https://github.com/aaronksaunders/Firebase3-ReactProject it can be done with some magic of plugins and polyfills...