Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use with json api #19

Closed
MikaAK opened this issue Apr 24, 2016 · 3 comments
Closed

How to use with json api #19

MikaAK opened this issue Apr 24, 2016 · 3 comments

Comments

@MikaAK
Copy link

MikaAK commented Apr 24, 2016

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?

@keichan34
Copy link
Owner

keichan34 commented Apr 24, 2016

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).

@MikaAK
Copy link
Author

MikaAK commented Apr 24, 2016

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!

@keichan34
Copy link
Owner

That's correct! I've opened a new issue about the docs I talked about before (#20). Re-open this issue if you're having any problems with the flow above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants