# File uploading with multipart

**URL:** <https://discuss.jsonapi.org/t/file-uploading-with-multipart/71>\
**Category:** Uncategorized\
**Created:** [July 28, 2015, 5:32pm UTC](https://discuss.jsonapi.org/t/file-uploading-with-multipart/71 "2015-07-28T17:32:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ShogunPanda](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/shogunpanda/32/45_2.png) [@ShogunPanda](https://discuss.jsonapi.org/u/ShogunPanda)\
**Post date:** [July 28, 2015, 5:32pm UTC](https://discuss.jsonapi.org/t/file-uploading-with-multipart/71/1 "2015-07-28T17:32:19Z")

</div>

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?  
Bye!  
Shogun

---

<div class="post-metadata">

**Author:** ![tkellen](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/tkellen/32/1_2.png) [@tkellen](https://discuss.jsonapi.org/u/tkellen)\
**Post date:** [July 28, 2015, 5:43pm UTC](https://discuss.jsonapi.org/t/file-uploading-with-multipart/71/2 "2015-07-28T17:43:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ShogunPanda](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/shogunpanda/32/45_2.png) [@ShogunPanda](https://discuss.jsonapi.org/u/ShogunPanda)\
**Post date:** [July 28, 2015, 6:19pm UTC](https://discuss.jsonapi.org/t/file-uploading-with-multipart/71/3 "2015-07-28T18:19:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dgeb](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/dgeb/32/17_2.png) [@dgeb](https://discuss.jsonapi.org/u/dgeb)\
**Post date:** [July 28, 2015, 7:39pm UTC](https://discuss.jsonapi.org/t/file-uploading-with-multipart/71/4 "2015-07-28T19:39:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ShogunPanda](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/shogunpanda/32/45_2.png) [@ShogunPanda](https://discuss.jsonapi.org/u/ShogunPanda)\
**Post date:** [July 30, 2015, 5:59am UTC](https://discuss.jsonapi.org/t/file-uploading-with-multipart/71/5 "2015-07-30T05:59:47Z")

</div>

Makes more sense.  
Ok, thanks for the feedback.

---

<div class="post-metadata">

**Author:** ![PaulTopping](https://avatars.discourse-cdn.com/v4/letter/p/e99b99/32.png) [@PaulTopping](https://discuss.jsonapi.org/u/PaulTopping)\
**Post date:** [November 28, 2015, 5:35pm UTC](https://discuss.jsonapi.org/t/file-uploading-with-multipart/71/6 "2015-11-28T17:35:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![yjaaidi](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/yjaaidi/32/329_2.png) [@yjaaidi](https://discuss.jsonapi.org/u/yjaaidi)\
**Post date:** [September 28, 2016, 1:23pm UTC](https://discuss.jsonapi.org/t/file-uploading-with-multipart/71/7 "2016-09-28T13:23:33Z")

</div>

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.

Younes
