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

POST in multipart/form-data unexpectedly becomes a GET #329

Closed
jkomyno opened this issue Apr 13, 2017 · 1 comment
Closed

POST in multipart/form-data unexpectedly becomes a GET #329

jkomyno opened this issue Apr 13, 2017 · 1 comment

Comments

@jkomyno
Copy link

jkomyno commented Apr 13, 2017

Versions

  • react-native: 0.43.0-rc.4
  • react-native-fetch-blob: 0.10.4
  • Android 7.1

Background

I have basically copied the structure of the code in the "Multipart/form-data example: Post form data with file and data" section of the README.md.

Use case

I have to download some files (PDFs or images) from a server and display them to the user.
At first I tried with a simple GET request from a local development server, and all went as expected (kudos to you guys!), but when I tried to achieve the same results with a remote API, I got this issue.

I have to use a POST with 'multipart/form-data' for downloading the images, which are dynamically selected according to the form data parameters.

At first, I did't get either a response or an error, so I set up a proxy in my system to intercept the HTTP requests and response in React Native and that's what I got:

So, even though I explicitly set that the request to /euclide/MandocSave should be a POST, react-native-fetch-blob uses a GET instead. Obviously, with a GET you can't have a body in the request, and without that body I can't use the API to obtain what I need.

Snippet

  RNFetchBlob
  .config({
    fileCache: true,
    addAndroidDownloads: {
      useDownloadManager: true,
      notification: false,
      mediaScannable : true,
      description: 'File downloaded by download manager',
    }
  })
  .fetch('POST', 'http://192.168.252.45:9080/euclide/MandocSave', {
    //'Content-Type': 'multipart/form-data',
  },
  [
    {
      name: 'Oper',
      data: 'S',
    }, {
      name: 'procedure',
      data: '*',
    }, {
      name: 'id_company',
      data: '122',
    }, {
      name: 'id_site',
      data: '165',
    }, {
      name: 'attachfilewspace_id',
      data: '853',
    }
  ])
  .progress((received, total) => {
    console.log('progress', received / total)
  })
  .then((res) => {
    console.log('it has responded', res.text());
    android.actionViewIntent(res.path(), 'application/vnd.android.package-archive');
    // RNFetchBlob.android.actionViewIntent(res.path(), 'image/*');
  })
  .catch((err) => {
    console.log('err@RNFetchBlob', err);
  });

Conclusion

How can I achieve my use case? I have already taken a look at the Troubleshooting section without success.
Any help or hint is really appreciated, thanks!

@wkh237
Copy link
Owner

wkh237 commented Apr 14, 2017

@jkomyno , thanks for the feedback. I think the problem is that you're using Android's Download Manager as such it becomes a GET request.

From Google's document I don't see anything allow us to change the method or its body.

However, I think if we can't support this one, we should put the extra detail in the document.

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