Error when POST file multipart/form-data
See original GitHub issueHi, I got an error every time when trying to POST data to the API. Request:
changeUserAvatar(authParam, file) {
let formData = new FormData();
//file is actually new FileReader.readAsDataURL(myId.files[0]);
formData.append('profile_image', file);
fetch(BASE_URL + 'profile-image', {
method: 'POST',
headers: {
'Content-Type': 'multipart/form-data',
'Authorization': authParam
},
body: formData
}).then((response) => {
return response.json();
}).then((response) => {
debugger;
}).catch((error) => {
console.error(error);
});
}
Error: profile_image can not be blank (422).
But it’s not blank!
Request payload:
What do I do wrong?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:7
- Comments:12 (1 by maintainers)
Top Results From Across the Web
Error when POST file multipart/form-data (JavaScript)
Solved at GutHub: https://github.com/github/fetch/issues/505. I just had to leave Header without pointing any Content-Type manually.
Read more >Error while upload a file with API using multipart form data
Hi Michael, We've seen this scenario (a 500 error when uploading multi-part data) in the past with customers integrating Blue Prism with Appian....
Read more >[Multipart/form-data] Getting a wrong media file typer error on ...
I have a REST service trying to send some text fields and a pdf to a third party for signing (Stiply). I keep...
Read more >[FIX]XMLHttpRequest error status 500 on POST multipart form ...
Please take 5' to look at this bug. Application using binary file Upload may not work with FF3, because the boundary field is...
Read more >"413 request entity too large" Errors
If you are the author of the script that generates the POST request, and it's submitting a file (or generating data similar in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Hashnode Post
No results found
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:Content-Type: multipart/form-data;boundary=----WebKitFormBoundaryyrV7KO0BoCBuDbTL
Fetch knows which content type header to create based on the
FormData
object passed in as the requestbody
content.@dgraham Thanks a lot! You saved a lot of my time 😃