Uploading to a RESTful API is much like uploading a file to any standard web form. Only without the GUI.
Starting with the basics, how the 'data' gets to be here is really none of the end-points concern. It expects some data in a certain way, and if what's provided matches what we accept then cushty. If not, well, we give them a friendly error message and send them on their way.
And the simplest way to accept a file to begin with is with getting our API end-point consumer to send in a base64 representation of their file.
There are reasons this may not suit you in real life. Apparently file sizes can be 33% bigger when base64 encoded. And we don't get a 'physical' file living on our disk that we can easily interact with in other ways, at least not without extra effort on our part. That's fair enough.
In this video we are just covering the easiest way (that I know of) to accept a file with the minimum of fuss.
tl;dr; we POST in a base64 encoded file as a string.
At this point we are also providing no way of having multiple images.
But as a quick fire solution, this works.
If you have found this video helpful, please consider sharing. I really appreciate it.
|1||Keeping it simple||04:01|
|2||Uploading a collection of things to a FOSRESTBundle API||11:24|
|3||Collections of UploadedFile||10:16|
|4||Collections of UploadedFile - Part 2 : Towards A Better Implementation||09:46|