File uploading with multipart


Hi all.
In the specification I read (and implemented) that the Content-Type header for both client and server MUST be application/vnd.api+json.

Now, here’s my question. When I’m uploading a file along with a JSON document, the only content-type I can foresee to use is the multipart/form-data, which seems to be conflicting with the specs.

Am I thinking it wrong? How can I fix this problem?

Handling Binary Data

Base64 encoding the binary data and including it in the JSON payload is a viable spec-compliant option.


Don’t you think this might be a unneeded overhead for mobile devices? Especially in SPA.


Your endpoint could also simply accept an alternative content-type. This would not conflict with the JSON API spec because the spec would simply not apply.


Makes more sense.
Ok, thanks for the feedback.


Makes sense to me. It seems to go along with JSON API’s stated goal of efficiency. Of course, this depends on the application. It still makes sense to load images in a web application. An API that returns an image might consider giving the caller the option of either receiving an image URL or the image itself, perhaps even choosing based on some caller-provided maximum size.

Disclaimer: I am only just getting into JSON API so I have no idea whether the above fits in well with its philosophy. Perhaps someone will respond and tell me.


Hello !

I think that for small files, it makes sense to include them inside the JSON request.

Otherwise, It would be nice to include in the standard the possibility to send a multipart requests where the first part would be application/vnd.api+json then you get the files afterwards.
The JSON part can contain metadata and information allowing the service to decide if it should read the following parts or not which can be an interesting performance boost.