colymba/silverstripe-restfulapi

Handling images via the APi

Opened this issue · 1 comments

Hi

I am trying to handle images via your API. I can read the API fine and get a URL to the image but trying to create a new image via a POST request doesn't seem possible?
I have my image in base64 format but not sure how to post this to the API?

I assume this isn't built in behaviour so I need to upload it via a custom ACL method? Do you have an example for how I create a custom method?

Thanks

It isn't built in at the minute... there is a plan for something like this to be included but not sure of the best way yet...

For now you got 2 options:

  • Create a new route to a special controller like upload: UploadController, which will handle the file upload and return a File ID.
  • Or use the new onBeforeDeserialize or onAfterDeserialize hooks, to catch your Base64 encoded file. So you could have your Base64 data in a json key like "rawFile": "018dar...", in the onAfterDeserialize grab the Base64 data and create a File, then remove the rawFile key and add a FileID to the deserialized payload