Question

I have an app that has both a web UI and mobile client on iPhone (Android coming soon). The user account page accepts a profile image, which just works with the Dragonfly gem. I'd like to let the iPhone client post a profile image using JSON api, because that's how it does everything else.

Is there a way to accept JSON values posted to and endpoint and create & store the image via Dragonfly?

Background details:
Rails 3.2
Ruby 1.9.3
Devise 2.0.3
Dragonfly 0.9.11
Heroku : Cedar stack
S3 for file storage

Was it helpful?

Solution

I'm putting this here in case it helps someone else.

Dragonfly image accessor accepts a string which is then saved as a file. You can then use it normally.

I POST'ed JSON data and passed the image binary contents as a string. In Ruby, IO.Read(FILE_NAME) to get the file contents.

To test, I posted the data with CURL. The json looked like this:
{"content": "...file content..."}

CURL Command:
curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d @encoded.txt http://localhost:3000/account/profile_images.json?auth_token={Devise Auth token}

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top