Skip to content
This repository has been archived by the owner on Mar 16, 2019. It is now read-only.

Upload to a Graphql (Graphcool) file endpoint #411

Closed
michaelspeed opened this issue Jun 26, 2017 · 6 comments
Closed

Upload to a Graphql (Graphcool) file endpoint #411

michaelspeed opened this issue Jun 26, 2017 · 6 comments

Comments

@michaelspeed
Copy link

michaelspeed commented Jun 26, 2017

i am facing problems with uploading to graphql(Graphcool) file endpoint.
RN - 0.45.1
react-native-fetch-blob - 0.10.5

snippet - (this one actually shows me the upload progress) -

    RNFetchBlob.fetch('POST', GRAPHCOOL_FILE_ENDPOINT, {
                'Accept': 'application/json',
            'Content-Type': 'multipart/form-data'
        },[
            {
                name: dates + 'mp4',
                filename: dates + 'mp4',
                type: 'video/mp4',
                data: RNFetchBlob.wrap(this.state.selectedVideo[0].uri)
            }
        ]).uploadProgress((written, total) => {
            console.log('uploaded', written/total)
        }).then((res) => {
            console.log(res);
            this.setState({
                textCamera:'',
                cameraActivityIndicator: false
            });
            this._onRefresh();
        }).catch((err) => {
            console.log(err);
        })

acutalluy i have tried with a lot of alterations -

{
  filename: dates + '.mp4',
  type: 'video/mp4',
  uri: this.state.selectedVideo[0].uri
}
{
  filename: dates + '.mp4',
  type: 'video/mp4',
  data: RNFetchBlob.wrap(this.state.selectedVideo[0].uri)
} 

the app crashes using the above.
only the snippet version shows me the progress, altought the file upload is complete and i also get a response but there is no file created at the endpoint.
can anyone help me here?

@wkh237
Copy link
Owner

wkh237 commented Jun 27, 2017

@michaelspeed , I'm wondering if that's because the file is large which exceeds the heap size limitation. How large are the files? Does this happen on both Android and IOS?

@michaelspeed
Copy link
Author

i say we tried with small 3mb and large 10-50mb files. i dont think its about the size, coz for the first one - { name: dates + 'mp4', filename: dates + 'mp4', type: 'video/mp4', data: RNFetchBlob.wrap(this.state.selectedVideo[0].uri) }

we get a upload progress, and the rest it just crashes

@wkh237
Copy link
Owner

wkh237 commented Jun 27, 2017

@michaelspeed , how does the URI looks like ?

@michaelspeed
Copy link
Author

///var/mobile/Containers/Data/Application/61725713-1F1A-4118-BB93-0DADB39F62D4/tmp/trim.08E78A1E-0C3D-4FC6-8A13-8913483259BA.MOV

using react-native-image-picker library

@rafaelcorreiapoli
Copy link

rafaelcorreiapoli commented Jun 30, 2017

Hey! I think I've found a workaround:

RNFetchBlob.fetch('POST', FILE_ENDPOINT, {
      'Accept': 'application/json',
      'Content-Type': 'multipart/form-data'
    }, [{
      name: 'data', // !!!HERE!!! must call "data"
      filename: 'anything_you_want',
      data: base64data
    }])
@michaelspeed
Copy link
Author

i can confirm the above is working!
i am closing this issue! if anyone has a better options they can reopen the issue!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.