I am developing a RESTful HTTP API based on ASP.NET Core 2 and the service will be used by a web frontend.
In the API there is a resource representing a file. It comes with some meta-data (id, name, folder) and can optionally contain raw binary data representing the file contents. The rest of the API uses JSON.
What is the modern approach to representing this resource in both requests and responses? The options I found so far are:
JSON with base64-encoded data
Pros: Easy to implement and use
Cons: The binary data can be up to multiple GB in size and Base64 would therefor massively inflate traffic as well asupload and download times, additonally the data would have to be encoded and decoded which would make the process rather slow
Split the resource into a JSON and binary subresource
Pros: Easy to implement and use
Cons: Two requests must be made to access all information
BSON
Pros: No Base64
Cons: Not as easy to handle on both server and client side as JSON, data is binary even when only non-binary data is sent, has to be encoded and decoded, requires additional dependencies, format would be different from the rest of the API
multipart/form-data with JSON and binary data
Pros: Binary and non-binary data can be split into JSON and binary data
Cons: Hard to handle, format would be different from the rest of the API