It would be a nice addition to have file upload capability for JSON API requests. This feature has been discussed, and argued over in the Core serialization and REST issue queues #1927648: Allow creation of file entities from binary data via REST requests, but hasn't made much progress. It seems like having some basic functionality to support this for the majority of simple cases would be a very useful thing to have.
Proposed resolution
The simplest solution I can see is as follows:
When POSTing (or PATCHing?) a file entity, permit a "data" attribute, which contains the Base64-encoded contents of the file to be created (or modified).
Obviously, this approach has limitations: There is overhead in request size due to the encoding. Also, you won't be uploading gigabyte-sized video files this way, as that will cause post_max_size or out-of-memory failures.
However, this approach has significant advantages: It works 100% inside the JSON API standard--no use of multi-part requests or binary data mixed into the request body. It's straightforward and probably understandable by most developers. And, it will work great for many use cases, such as image uploads. Documentation could be used to clarify this method's limitations.
Developers who need support for larger files could still write custom code, perhaps create a separate upload API, etc. Any thoughts on this proposal?
Comments
Comment #2
hampercm commentedComment #3
grimreaperDuplication with #2785345: [FEATURE] Provide support for uploading files?
Comment #4
hampercm commentedWhoops, wasn't aware of that other issue :P
Combining the info and closing this one out.