I storing images using paperclip + S3
has_attached_file :image,
:whiny => false,
:styles => { :large => "550x340>",
:medium => "165x165>",
:small => "100x100>",
:thumbnail => "55x55>"},
:processors => [:cropper],
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => "/:id/:style",
:bucket => "XXX"
when I create an object with image every thing goes fine (4 copies of the image with 4 different sizes stored in my S3 Bucket )
The problem comes when I crop the image using JCrop, S3 store 4 copies but with the same size for the cropped image actually the large size.
My controller.rb:
def update
@deal = Deal.find(params[:id])
respond_to do |format|
if @deal.update_attributes(params[:deal])
format.html { redirect_to(@deal, :notice => 'Deal was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @deal.errors, :status => :unprocessable_entity }
end
end
This is how it works:
Now, most optimal way I can think of is to upload the cropped image with a new file name. So that when CDN checks its cache, it doesn’t find it there and asks s3 for the file. You can delete the old file in background using delayed_job or resque.
Hope, it clarifies things.