wkh237 / rn-firebase-storage-upload-sample

React Native sample code for upload blob data to Firebase using Firebase SDK with RNFetchBlob.
57 stars 13 forks source link

Firebase Storage: Invalid argument in `put` at index 0: Expected Blob or File. #3

Closed smilechun closed 8 years ago

smilechun commented 8 years ago

Once the upload statement fire, it return: Possible Unhandled Promise Rejection (id: 0): Firebase Storage: Invalid argument in put at index 0: Expected Blob or File.

Please help.

code snippet:

let images = this.state.images; let uri = images[0].path.uri; let type = uri.substr(uri.lastIndexOf('.') + 1); let rnfbURI = RNFetchBlob.wrap(uri);

    let filename = new Date().getTime().toString();

    console.log(uri, type, filename);

    // create Blob from file path
    Blob
        .build(rnfbURI, { type : 'image/' + type + ';'})
        .then((blob) => {
            console.log(blob);
            // upload image using Firebase SDK
            firebase.storage()
                .ref('users')
                .child(filename)
                .put(blob, { contentType : 'image/' + type })
                .then((snapshot) => {
                    console.log('Done.');
                    console.log(snapshot);
                    blob.close();
                })
                .catch((err) => {
                    console.log(err);
                    blob.close();
                })
        });
smilechun commented 8 years ago

The problem is solved. I forgot to add the following statements. window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest window.Blob = Blob

but another error thrown:

ExceptionsManager.js:61 Firebase Storage: An unknown error occurred, please check the error payload for server response.

After the investigation, it is the same problem as Crashes with larger images

wkh237 commented 8 years ago

@smilechun , thanks for report, we're working on the issue 😄

MrRoyce commented 8 years ago

@smilechun where those images that you uploaded to Firebase from the CameraRoll on a device?

I've not been able to get images from my CameraRoll to upload to Firebase. I filed an issue here https://github.com/wkh237/react-native-fetch-blob/issues/109