Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Damian Sieczkowski
Damian Sieczkowski
9,730 Points

What's the best approach for receiving photos from a mobile client to a Rails backend?

I'm working on the backend for a iOS application and a few of the models are meant to contain photos - how do I handle that?

1 Answer

Ultimately it depends on where you want to store your photos. I'd venture to say that the most common scenario is storing the photos in the cloud somewhere (e.g. AWS S3). If that is the case then you'd use the AWS Mobile SDK to upload the image, save the URL, and then pass that information to your Rails backend.

If you want to store the file using the Rails backend, either as a BLOB in the database or on the local file system then you'd need to send the data of the image through an HTTP call. I've not personally verified the code in this post, but it might help you get started: https://zunostudios.com/blog/development/143-how-to-upload-a-photo-using-nsurlconnection

Damian Sieczkowski
Damian Sieczkowski
9,730 Points

Awesome, thanks. That's very insightful.

Damian Sieczkowski
Damian Sieczkowski
9,730 Points

If you have time, would you be able to share your thoughts on this question as well ==> https://teamtreehouse.com/forum/authorization-for-rails-api ?