Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Content-Type: application/json not working for multipart MIME requests #1576

Closed
ctalibard opened this Issue · 3 comments

3 participants

@ctalibard

I want to be able to send two parts to my REST API, one containing RAW JSON data representing attributes of a file and a second containing the actual file.

Despite defining the Content-Type of the first part as application/json (like I would for a non-multipart request) Express is still parsing it as a string and setting a single field in req.body to contain that string.

My HTTP request is formatted like this:

Content-Type: multipart/form-data; boundary=xxxx

--xxxx
Content-Disposition: form-data; name="json"
Content-Type: application/json

{ some: "JSON", to: "parse" }

--xxxx
Content-Disposition: file; filename="theFile"
Content-Transfer-Encoding: binary

File contents here
--xxxx--

I would hope that req.body would be the JSON I sent, but instead it's:

{ json: "{ some: \"JSON\", to: \"parse\" }" }

Is there a special Content-Disposition I should be using to make this work?

@ctalibard

Thinking about this, it seems likely that the HTTP multi-part MIME spec/RFC just doesn't allow for anything other than form data, which is a shame.

@tj
tj commented

formidable doesn't parse the parts themselves beyond files AFAIK, so for now you just get the "raw" data

@jonathanong

express 3.4 now uses multiparty instead. if you want this feature, you should file an issue there.

@jonathanong jonathanong closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.