question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

body parameters arrived empty to the server API

See original GitHub issue

Hi guys,

Great work, I have issue, when do uploading blob, as multipart request, the other fields in body arrived empty at server side when doing upload from IOS, on android it just work fine,

let cleanFilePath = feedItem.media.path.replace('file://', '');
const body = [
				{
					name: 'data',
					data: JSON.stringify(feedItem),
					type: 'application/json'
				},
				{
					name: 'file',
					filename: mediaFileName,
					data: RNFetchBlob.wrap(cleanFilePath),
					type: mediaFileType
				}
			];

			RNFetchBlob.fetch('POST', request.url, {
				'Content-Type': 'multipart/form-data',
				Authorization: (auth) ? 'Bearer ' + auth.accessToken : ''
			},
				body).uploadProgress({ interval: 5000 }, (written, total) => {
					console.log('uploaded', written / total)
					dispatch({ type: 'FEED_ITEM_COMPOSER_CREATE_PROGRESS', payload: Math.round((written / total) * 100) + '' });
				})
				.then((res) => {...............

Any idea why data parameter, received empty by the server API for IOS only?

Edit: This happen only when calling https API, when changing the link to http, it worked.

Thanks

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

4reactions
rodgomesccommented, Oct 25, 2019

change 'Content-Type': 'multipart/form-data', to 'Content-Type': 'application/json',

and you body var need to look like this:

 const body = JSON.stringify([
      {
        name: 'data',
        data: JSON.stringify(feedItem),
        type: 'application/json',
      },
      {
        name: 'file',
        filename: mediaFileName,
        data: RNFetchBlob.wrap(cleanFilePath),
        type: mediaFileType,
      }
    ]);
0reactions
Joelito1031commented, Oct 2, 2021

POST method did the trick for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Trying to send body parameters but req.body is empty
I got the solution to the problem I had mentioned, in this case, I needed to use params from the Get method.
Read more >
Build a Hello World REST API with Lambda proxy integration
Learn how to build and test an API with Lambda proxy integration using the API ... Create an empty API as follows: ......
Read more >
Add a Request Body to a POST Request | API Connector
A content-type header describes the object's format, so the server knows how to ... If you need to send an empty request body,...
Read more >
Method: people.get | People API - Google Developers
Got it. On this page; HTTP request; Path parameters; Query parameters; Request body; Response body; Authorization Scopes; Try it.
Read more >
API return empty body - Confluence Data Center
Hi All, I am using Confluence REST API, is it possible to get the content from the wiki? I can access it but...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found