Search code examples
fetchmultipartform-dataform-datahttp-status-code-415

415 on fetch POST with multipart FormData


I have been going over countless posts and I am just stumped with this which should be so simple.

let formData = new FormData();
formData.append('message', payload.message);
formData.append('attachment', this.state.attachment);
let options = {
    method: 'post',
    body: formData
}
fetch('api/contact', options);

Then I get the all too familiar 415 error:

Request URL: https://localhost:44348/api/contact
Request Method: POST
Status Code: 415 
Remote Address: [::1]:44348
Referrer Policy: no-referrer-when-downgrade

I know not to set my Content-Type and even the headers and everything look fine including the boundary:

Request Headers

:authority: localhost:44348
:method: POST
:path: /api/contact
:scheme: https
accept: */*
accept-encoding: gzip, deflate, br
accept-language: en-US,en;q=0.9
cache-control: no-cache
content-length: 10269
content-type: multipart/form-data; boundary=----WebKitFormBoundary5iTqTV6AaKla3BMA
origin: https://localhost:44348
pragma: no-cache
referer: https://localhost:44348/contact
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: same-origin
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36

Form Data

message: asdasd
attachment: (binary)

This is the same API I previously used with and old jQuery site and it worked fine. Any ideas?


Solution

  • The older version of Core was not case sensitive when parsing incoming models, the newer version is.