I know I that I can post multipart/form
data with boundaries via HTTP POST.
What I’m looking to confirm, and possibly get a review of, is posting a file as a base64 string as part of a larger JSON object. For example:
[
{
data: {
type: documents,
lid: 0,
attributes: {
foo: string,
bar: integer,
file: data:mime/type:ZmlsZWRhdGEK...
...
...
}
},
{
data: {
type: documents,
lid: 1,
...
}
},
{
data: {
type: documents,
lid: 2,
...
}
}
]
The file here could be a video, an excel document, an image, anything in a given set of mime types.
My initial approach is to “pair” an application/vnd.api+json
(jsonapi.org) array of resources and loop through it and individual files also posted, matching the file name (or lid
) to populate the associated metadata in the repository for each file in a “nested for loop.” So for n
(number of files) a + 1 (json-body) document in the POST multipart/form data.
The files in question could be initially 80MB, limited by the email platform, and we could see in the future files in the GBs. Truthfully, maybe encoding a 10GB video file is highly inefficient with a large memory overhead (nevermind compressing, e.g., gzipped, on the wire by default).
Another option considered is just sending every file singly with a json-api body, so each post represents the file and metadata. More requests, but simpler handling. In other words a form accepting n documents with meta-data details would iterate n times for each file and meta-data to the API endpoint.
Would love feedback if you’ve ever faced this problem before and have ideas.