Right now in my rails app I'm using Carrierwave to upload files to Amazon S3. I'm using a file selector and a form to select and submit the file, this works well.
However, I'm now trying to make posts from an iPhone app and am receiving the contents of the file. I'd like to create a file using this data and then upload it using Carrierwave so that I can get the correct path back.
May file model consists of:
path
file_name
id
user_id
where path is the Amazon S3 url. I'd like to do something like this to build the files:
data = params[:data]
~file creation magic using data~
~carrierwave upload magic using file~
@user_id = params[:id]
@file_name = params[:name]
@path = path_provided_by_carrierwave_magic
File.build(@user_id, @file_name, @path)
Would really love someone to point me in the right direction. Thanks!
Here is what I wrote to perform an upload to s3 from an ios application through carrierwave :
First the Photo model
Second in the Api::V1::PhotosController
Then the call from my iPhone application using AFNetworking
In the JSON response I can get the new instance of Photo with the image.url attribute set to the url in the s3.
Alright, I have a working solution. I'm going to best explain what I did so that others can learn from my experience. Here goes:
Assuming you have an iPhone app that takes a picture:
On the rails side I set up a method specifically for handling mobile images, this should help you post the image to your Amazon S3 account through Carrierwave:
This works for me for posting and I feel should be pretty extendable. For the class methods:
Not saying this code is perfect, not even by a longshot. However, it does work for me. I'm open to suggestions if anyone thinks it could be improved. Hope this helps!