I am uploading image via jquery_file_upload (Railscast episode #383) The upload work perfectly and i get the url in the callback function
The problem is: I want to create some thumbnails after uploading directly to s3
for that i assume:
Now, after the image finish to upload the image controller callback called:
def create
#get the url from the callbcack
#e.g: image[image_source] = https://<BUCKET>.s3.amazonaws.com/uploads/myimage.png
@image = Image.new(params[:image])
@image.user_id = current_user.id
@image.save
end
And the model:
class Image < ActiveRecord::Base
attr_accessible :image_thumb, :user_id, :width ,:album_type_id
after_save :enqueue_image
mount_uploader :image_thumb, ImageUploader
def enqueue_image
#checking if i have the original image
if self.image_source present?
#what to do here?
#how can i call the carrierwave function to create the thumbnails?
#how to send the thumbnails directly to s3 with callback name?
end
end
end
Do you necessarily need to create the thumbnails after uploading? If not, I think that you can create a thumbnail (or as many sizes as you want) during the initial upload by using version
. Example:
class ImageUploader < CarrierWave::Uploader::Base
version :thumb do
process :resize_to_fill => [50, 50]
end
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.