Save thumbnail image directly to S3 in Rails - ruby-on-rails

I'm using an API to grab a thumbnail image. The API request automatically downloads the image. I'd like to store that image directly in my S3 bucket. It seems like overkill to use something like Carrierwave for this. How can I make the API call and save the image directly in S3?

Install the AWS S3 gem
sudo gem i aws-s3
and configure it by following the instructions here.
http://amazon.rubyforge.org/
then
S3Object.store('image.jpg', open('fileName.jpg'), 'bucketName')

Related

Rails s3_direct_upload how to disable it

In Rails, I am using s3_direct_upload gem for asset(doc file) upload. Right now if I try to upload an image file as a different asset, it is directly uploading to s3. I need to disable this option for image upload and it should be enable only for document upload.
s3_direct_upload is provides form helper methods to upload images to s3 directly. like this s3_uploader_form. It just reduces your jquery_file_upload and s3 configuration.
But you can still upload image to your local file system. Using simple form_tag. i.e. When you want to upload images to s3 use s3_uploader_form syntax and when you want to upload images to local file system then use simple form_tag or any other rails provided form syntax.
For uploading images using ajax use remotipart gem with simple form syntax.

Uploading image from PhoneGap to Carrierwave / Rails 3?

I'm trying to figure out the best way to upload a camera image from a PhoneGap app to a Rails 3 app that has Carrierwave on it. My thoughts so far:
Option 1) Use phonegap filetransfer functionality to upload to a temp folder on S3 then assign the URL to the remote_avatar_url for my carrierwave field. Then carrierwave does all the work for me in terms of grabbing the image, resizing, cropping, etc. Carrierwave will then send the files back over to S3 where they will be stored in the right places.
Option 2) Use phonegap filetransfer functionality to upload directly to my rails server then let carrierwave do the work from here. This seems more efficient, but I don't know how to assign an image that was posted to a rails api controller to Carrierwave so that it can do its thing. Any ideas assuming this is the best way to handle?
Thanks!
You can send the image as Base64/encode and than parse it on the CarrierWave side. Take a look at http://ograycoding.wordpress.com/2012/07/03/api-upload-with-carrierwave/

Uploading Images without using ImageMagick

I don't want to have to configure imagemagick but want to use a gem to be able to upload a picture from a form and put it into a database. Are there other options out there? I tried dragonfly and carrierwave but they require ImageMagick.
I often use Blitline which allows we to me to make any edits to the image (if needed) and then I have Blitline store it in an Amazon S3 bucket and place the image url in my database to save space in the database.

How to upload binary data to Amazon S3 from a Rails app?

I am using the gems Paperclip & aws-s3 to upload images to Amazon S3 from my Rails app. This all works fine. What I am now trying to do is upload some binary data to S3 and return the URL. How can I do that?
You'll find a tutorial with examples here:
http://amazon.rubyforge.org
Look at the S3Object.store method.
EDIT:
You should now use the official Amazon SDK:
http://aws.amazon.com/sdkforruby/

Paperclip: migrating from file system storage to Amazon S3

I have a RoR website, where users can upload photos. I use paperclip gem to upload the photos and store them on the server as files. I am planning to move to Amazon S3 for storing the photos. I need to move all my existing photos from server to Amazon S3. Can someone tell me the best way for moving the photos. Thanks !
You'll want to log into your AWS Console and create a bucket structure to facilitate your images. Neither S3 nor Paperclip have any tools in the way of bulk migrations from file system -> s3, you'll need to use the tool s3cmd for that. In particular, you're interested in the s3cmd sync command, something along the lines of:
s3cmd sync ./public/system/images/ s3://imagesbucket
If you have any image urls hard-coded into your database (a la markdown/template code) this might be a little tricky. One option would be to manually update your urls to point to the new bucket. Alternatively, you can rack-rewrite.
You can easily do this by creating a bucket on Amazon S3 that has the same folder structure as your public directory on your Rails app.
So say for instance, you create a new bucket on Amazon S3 called MyBucket and it has a folder in it called images. You'd just move all of your images within your Rails app's images folder over to that new bucket's images folder.
Then you can set up your app to use an asset host like this answer describes: is it good to use S3 for Rails "public/images" and there an easy way to do it?
If you are using image_tag or other tag helpers (javascripts, stylesheets, etc), then it will use that asset_host for production environments and properly generate the URL to your S3 bucket.
I found this script which takes care of moving the images to Amazon S3 bucket using rake task.
https://gist.github.com/924617

Resources