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.

Multipart request (FormData) not work in iOS

See original GitHub issue

with Android it’s working perfectly, i don’t understand why it’s not working in iOS (all ios version), don’t have any parameters transfer to the API server:

THE LOG REQUEST IN SERVER:

Files: "" ; group receipents: "" ; User receipients: ""

The CODE:

const localUploadAttachment = async (url, a, message) => {
    let formData = new FormData();
    let dataObj = {
        name: a.name,
        type: 'image/jpg',
        uri: a.uri
    };
    formData.append('files', dataObj); // i tested with "file" parametter but its still not work
    formData.append('groupRecipients', JSON.stringify(message.GroupRecipients));
    formData.append('userRecipients', JSON.stringify(message.UserRecipients));

    let response  = fetch(url, {
	method: "POST" ,
	timeoutInterval: 30000,
	body: {
	      formData: formData,
	},
	sslPinning: {
	      certs: ["mycert1"]
	},
	headers: {
		'content-type': 'multipart/form-data; charset=UTF-8',
		accept: 'application/json, text/plain, /',
	}
    })

    return response;
}

The LOG API REQUEST:

log-api-request

Please take a look and let me know if you have anything solution for that. Thanks 😃

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:31 (16 by maintainers)

github_iconTop GitHub Comments

3reactions
MaxToybermancommented, Oct 23, 2020

@canhtran10 @castalonirenz i have just upload some files i know what was the issue :

  1. remove ‘content-type’: ‘multipart/form-data; charset=UTF-8’, from headers. Setting the Content-Type header manually means it’s missing the boundary parameter. Remove that header and allow fetch to generate the full content type. It will look something like this:

2)data: response.data is not needed

i will update the docs.

your code should look like this :

     let formData = new FormData();
                  let dataObj = {
                      name: a.name,
                      type: 'image/jpg',
                      uri: a.uri
                  };
                  formData.append('file', dataObj); // i tested with "file" parametter but its still not work
                  formData.append('groupRecipients', JSON.stringify(message.GroupRecipients));
                  formData.append('userRecipients', JSON.stringify(message.UserRecipients));

                  let response  = fetch(url, {
                    method: "POST" ,
                    timeoutInterval: 30000,
                    body: {
                          formData: formData,
                    },
                    sslPinning: {
                          certs: ["mycert1"]
                    }
                      })

Please let me know if it worked for you

1reaction
castalonirenzcommented, Oct 28, 2020

Thanks, will try it tomorrow for sure.

Read more comments on GitHub >

github_iconTop Results From Across the Web

multipart/form-data not working anymore, missing filename
I have a function to upload an image using multipart/form-data that was working before, today it stopped working for whatever reason.
Read more >
POST multipart/form-data with Obje… | Apple Developer Forums
I have used the multipart/form-data POST on iOS & I had written the following code and it is uploading data but not image...
Read more >
[Android] FormData fails to send data in multipart/form-data
On Android, the request is made but both image and description are missing from the request. let formData = new FormData(); formData.append(' ...
Read more >
How To Upload Data To A Server: Multipart/Form-Data HTTP ...
MultipartFormDataRequest is very similar to a URLRequest in that it is initialised by a URL. The URL endpoint that you will be sending...
Read more >
FormData.append() - Web APIs | MDN
The append() method of the FormData interface appends a new value onto an existing key inside a FormData object, or adds the key...
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