Uploading directly to S3 and resizing the images - ruby-on-rails

I'm using s3_direct_upload to directly upload images from my rails app to an S3 bucket. This is all working fine, however now I'd like to resize the images once uploaded, creating a thumbnail and various other versions.
The approach I can think of taking is using the URL that's posted back from s3_direct_upload to then create a new object in my app in the background, process using RMagick and then reupload these versions to S3. However, this approach feels like the initial upload becomes a little redundant.
Any advice on this or a better approach would be greatly appreciated.

Updated Answer
You mentioned in a comment to my original answer that you'd tried CarrierWave. But...have you tried out CarrierWaveDirect? I haven't used it myself, but it appears to perform the same S3 direct-uploading, with the familiar API of CarrierWave.
Original Deprecated Answer
You'll probably want to look into either Paperclip or Dragonfly. They each support uploading images to S3 (or other cloud storage provider), and also provide features for manipulating the images. The two solutions handle manipulations in different ways--Paperclip performs thumbnailing at upload-time, whereas Dragonfly performs thumbnailing on-the-fly--but either should meet your needs.

Related

configure paperclip to generate styles when they are requested

I need a user to upload an original file and process that into a thumbnail (paperclip's got this - check).
Then I would like to be able to retrieve different styles for that attachment, but I do not need to store those different styles on disk anywhere. I would prefer they are generated during the request.
The reason for that is that these styles are single-use. So, paperclip becomes a glorified one-time-use image resiszer. I'd prefer not to incur the S3 cost if I don't have to.
Wondering if there'a way to do this out of the box. Or, maybe carrierwave supports something like this?
Thanks!
I'm pretty sure that the Refile library supports it. Refile is basically a modern version of the Carrierwave, written by the same author.
You can read more about the on-the-fly processing here:
https://github.com/refile/refile#processing

What are my options for resizing an image in my rails application?

I would honestly appreciate feedback, or an on edit, on what I should change about this post instead of all the down votes. I'm new to web development, and I had an honest question. If this isn't the place to ask it, please point me in the right direction.
I have a Ruby on Rails application where part of the core purpose involves displaying images that I pull from the Facebook Graph API. And I want to be able to display the images in a uniform size.
What I'm hoping I can do: I'm trying to just store the id of the image from Facebook to my database and resize the image after I pull it from Facebook's servers. I was thinking that this would save on storage costs. I've been looking at the RMagick gem that binds Ruby to the ImageMagick library, specifically their resize method.
Another option I've considered: I'm thinking about adding a cropping feature. To do this though, I think I would need to set up a storage service, like Amazon's S3. Then I would pull from the image storage service where the cropped images are stored instead of pulling from Facebook and resizing client-side.
Are there any options I might not be considering? And how accurate are my examples to approaches that could be taken.
If you have a huge number of images to show, then go with "resize - store - show". If less then go with an on-the-fly process.
Here are a few well-known gems that help you process images, but choose according to your requirement:
CarrierWave
Paperclip
Dragonfly
refile (new gem)
See "Compare CarrierWave ,Paperclip and Dragonfly in rails" and "Refile: Fixing Ruby File Uploads".

Best approach to Users Profile Images in Rails App

I am new to Rails and have been diving into many tutorials and online material. I am now beginning to plan/develop my own app. From all the reading I have done I am yet to come across an industry standard way of handling user profile pictures. I have bullet point what I intend to do (below) and would like some suggestions whether this is a good approach and on the right track or whether there is a much better/secure/standard way:
add a 'ProfilePhotoPath' column to my User Model/Table of type String, which will hold the location path/name of the photo
on sign-up form implement an image upload functionality to upload profile pic and store at specified location (reference in step 1 above)
note: I have come across the 'paperclip gem' and 'imagemagick', is this a better easier approach to what I want to achieve?
There are two better ways to upload profile image using Carrierwave or Paperclip.
If you want to use Carrierwave then refer this tutorial Image Upload using Carrierwave
And if you want to go for Paperclip, then refer this links Upload image using Paperclip video tutorial
Another link with steps is Upload profile image using Paperclip
Most people use Paperclip or a more robust solution would be Carrierwave.
Both are really good. I would tell you to learn Paperclip first.
It's fairly easy if you're just starting out.
Edit: checkout this link. Click the green 'run' button to see the app.
http://runnable.com/UnnhcBiQoFhwAAEb/how-to-upload-files-using-paperclip-for-ruby-on-rails

Which is the best route to take when uploading images from my Rails app to Amazon's S3?

I have a web app in which users can upload an avatar under 700kb. That's the only part of the application dealing with uploading images (so I won't be dealing with an exceptionally heavy load). I was wondering what the best way is to go about this. Currently I'm using Paperclip and I wan't to store all of the images on Amazon's S3.
Option 1: User uploads the image to my web server. The image is processed asynchronously using delayed job and is then uploaded to s3. The image is then deleted off of my web server.
Option 2: User uploads the image directly to s3. A background process on my web server downloads the image, processes it, and uploads the newly created thumbnails to s3.
Option 1 seems to use less bandwidth overall. Option 2 seems to save my application the resources of having the image uploaded directly to it.
Am I correct in these assumptions? Which option is the fastest and most resource-friendly? Or is there another way to go about this?
Also, I was wondering if sites like Twitter, FB, and Posterous asynchronously process images. Whenever I upload a profile pic on Twitter, or images on FB and Posterous, they seem to be processed instantly.
Thanks!
Tim
Your best bet is to have the user upload directly to S3. The d2s3 plugin works well for this.
In your d2s3 callback, create a delayed_job event to download the full size images and save thumbnails them to S3 with Reduced Redundancy Storage. If you wire everything up correctly, you can automatically generate thumbnails when and if they're ever lost from S3.
If by "processing image", you mean creating thumbnails or other image conversion options, you can do that using paperclip. If processing is a huge task that can't be achieved using paperclip alone, then I would go with option 1, cheaper as you don't access S3 multiple times. Just make sure you have enough hard disk space for all images during processing.
If you end up going the route of uploading directly to S3 which offloads the work from your Rails server, please check out my sample projects:
Sample project using Rails 3, Flash and MooTools-based FancyUploader to upload directly to S3: https://github.com/iwasrobbed/Rails3-S3-Uploader-FancyUploader
Sample project using Rails 3, Flash/Silverlight/GoogleGears/BrowserPlus and jQuery-based Plupload to upload directly to S3: https://github.com/iwasrobbed/Rails3-S3-Uploader-Plupload
By the way, you can do post-processing with Paperclip using something like this blog post describes:
http://www.railstoolkit.com/posts/fancyupload-amazon-s3-uploader-with-paperclip

Image upload options for website users

I want to be able to provide my website users with the ability to upload a profile picture. What are my options? What is the best way to do this? I would need to be able to limit the image size, crop / resize the image so that I can display thumbnails of the image. The website is written using Ruby on Rails
In alternate plugin to manage your upload file is carrierwave
The PaperClip plugin is pretty much the new hotness (standard):
http://github.com/thoughtbot/paperclip
It supports different image processors but we use ImageScience. RMagick leaks memory
I agree with the others recommendation of Paperclip for handling any kind of upload.
However for profile pictures in particular, if you are storing your user's email addresses you might like to consider using Gravatar, as StackOverflow does, to effectively "outsource" this functionality and let your users maintain consistent avatars among all the sites they use.

Resources