How to use with json api
MikaAK opened this issue · 3 comments
I'm wondering how i can integrate this into a phoenix json api, to be exact I'm not sure how to upload a photo to a specific model. In the example, it shows you can do foward "/attachments", Exfile.Router
but how would I do this on a per resource basis so that I can upload files for my User models avatar field for example?
I'll make a JSON-based usage guide in the near future. When you upload to /attachments (usually to the cache store, so POST /attachments/cache
) outside of the traditional request/response cycle, you will get back a JSON document with the structure:
{
"id": "file ID",
"uri": "exfile://cache/file ID"
}
You can then use the uri
field to associate that file with the user avatar field using the Ecto field (the Ecto adapter will recognize the exfile://
URI and copy the file from the cache backend to the store backend).
Thanks for the quick response. Just to make sure I understand, an upload process would look something like this:
POST /attatchments/cache
-> take uri and update User model with {avatar: uri}
-> file gets moved from cache into actual store.
I like the sound of that!