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

RNFetchBlob.fetchBlobForm failed to create request body #437

Open
hstoebel opened this issue Jul 19, 2017 · 15 comments
Open

RNFetchBlob.fetchBlobForm failed to create request body #437

hstoebel opened this issue Jul 19, 2017 · 15 comments

Comments

@hstoebel
Copy link

hstoebel commented Jul 19, 2017

React-Native: 0.46.3
RNFB: 0.10.6

I am trying to upload a selected image from the camera roll using react-native-image-picker. The following works fine on Android but on ios I get warning: Error: RNFetchBlob.fetchBlobForm failed to create request body. Any idea what I'm doing wrong?

    ImagePicker.showImagePicker(options, (response) => {
      if (response.didCancel) {
        console.warn('User cancelled image picker');
      }
      else if (response.error) {
        console.warn('ImagePicker Error: ', response.error);
      }
      else if (response.customButton) {
        console.warn('User tapped custom button: ', response.customButton);
      }
      else {

        RNFetchBlob.fetch('POST', 'http://12.34.56.78:3000/upload', 
          {'Content-Type' : 'multipart/form-data'}, 
          [
            { name : 'from_device', filename : 'from_device.png', type:'image/png', data: RNFetchBlob.wrap(response.uri)},
          ]
        ).then((resp) => {
          console.warn(resp);
        }).catch((err) => {
          console.warn(err);
        })
@wkh237
Copy link
Owner

wkh237 commented Jul 25, 2017

@jstoebel , I'd like to know how is the image's URI look like, perhaps it's caused by #287 .

@hstoebel
Copy link
Author

hstoebel commented Jul 25, 2017

@wkh237 I took a look at response.uri in the console and here's what I got:

console.warn(response.uri);
// file:///Users/user_name/Library/Developer/CoreSimulator/Devices/C360DD7C-D60…C30-D5757191483B/Documents/images/E858BC4A-2B68-4FFC-9103-8A9081EDBA08.jpg

console.warn(RNFetchBlob.wrap(response.uri));
// RNFetchBlob-file://file:///Users/stoebelj/Library/Developer/CoreSimulator/D…C30-D5757191483B/Documents/images/E858BC4A-2B68-4FFC-9103-8A9081EDBA08.jpg

Is the problem something to do with the repeated file:// in the wrapped uri? Sorry if there is something I'm missing.

@wkh237
Copy link
Owner

wkh237 commented Jul 25, 2017

@jstoebel , perhaps that's exactly what we're going to do in #387, please try to stripe file:// on IOS.

@antondomratchev
Copy link

@wkh237 Were you able to track down what is the root cause of the issue? I would like to help out by making a PR to fix this issue.

@wkh237
Copy link
Owner

wkh237 commented Jul 25, 2017

Because IOS file system does not recognize the file:// URI in the native, so you will need to strip that manually, this is what React Native used to behave in 0.2x. Well, I have to say this is confusing, will fix it once I have time.

@isAlmogK
Copy link

isAlmogK commented Aug 7, 2017

I'm having the same issue and removing file:// from the URL does nothing and I'm still getting the same error

let cleanUri =  string_.ltrim(newPhoto.uri, "file:///");
console.log(cleanUri) 
RNFetchBlob.fetch('POST', 'https://api.claudia.constructioncloud.io/teams/' +selectedTeam.id+ '/photos', {
                    Authorization :  `JWT ${accessToken}`,
                    'Content-Type' : undefined, //'multipart/form-data',
                }, [
                    // part file from storage
                    { name : 'file', filename : 'avatar-foo.png', type:'image/jpg', data: RNFetchBlob.wrap(cleanUri)},
                ]).then((resp) => {
                    console.log(resp);
                }).catch((err) => {
                    console.log(err);
                })

@isAlmogK
Copy link

isAlmogK commented Aug 7, 2017

I was able to debug this I had the following setting for options under image picker

// Options for photos and videos
const options = {
    title: 'Select',
    noData:true,
    mediaType:'mixed',
    storageOptions: {
        skipBackup: true,
        path: 'construction cloud'
    }
};

path: 'construction cloud'
was casuing my issue, I just changed it to path: 'construction-cloud'

@Nealyang
Copy link

I have this same issue

@lll000111
Copy link
Contributor

@Nealyang What issue? I see two issues above and both seem to have been addressed. Did you try what helped the others?

@fabriziomoscon
Copy link

@AlmogRnD you replaced file:/// not file:// (3 slashes)
replacing 2 slashes I managed to read the file on iOS

@DmytroBatyuk
Copy link

DmytroBatyuk commented Jan 26, 2018

FYI: for me PATCH works perfect but not POST. So I think bug is inside the package

@ospfranco
Copy link

striping the file:// fixed my issues, but I think this should be patched on library level, any news on this?

@lll000111
Copy link
Contributor

@ospfranco

any news on this?

Read the README? :-)

@delvinmc20
Copy link

FYI: for me PATCH works perfect but not POST. So I think bug is inside the package

That works for me, Thanks.

@vaqif14
Copy link

vaqif14 commented Dec 13, 2018

i solved with string.replace('file://', '')

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

No branches or pull requests