Hi all,
I'm in the final stages of my API development and one thing I can't really wrap my head around is handling file uploads.
My use-case is the following:
I have a resource which may have n properties that are "files" (picture for a product, PDF contract for a customer, etc).
GET response to the resource is something like this:
.../myapi/products/:ID
{"name": "Name ", "otherParameter": "value", "picture": {"webPath": "http://...", "thumbNailPath": "http://...", "title": "sometitle", ...}}
Basically, picture property is a value-object containing information about the file.
My question is, how to handle POST/PUT/PATCH'ing this resource.
Is it against some API design principles that the sent value-object is completely different from the returned one, i.e. {..., "picture": {"content": "complete file content", "name": "pic.jpeg", "mimetype": "image/jpeg"}}?
Is it more of a good practice to use a separate property for uploading a file, i.e. {..., "pictureUpload": {...}}. But this doesn't make much sense to me, because I want to set a picture property, not some kind of a virtual property called pictureUpload.
I know how dropbox handles this, but they have a separate endpoint for uploading a file (file itself is the resource) but that seems overkill to my use-case.
How do you guys handle these kind of things? Are there any examples for such situations in other API's?
Any input from you guys is appreciated.
Miko