Ruby on rails 如何在使用jquery file upload将原始文件直接上载到s3后使用carrierwave创建缩略图
我通过jquery_文件上传图像(Railscast第383集) 上传效果很好,我在回调函数中得到了url 问题是:我想在直接上传到s3之后创建一些缩略图 为此,我假设:Ruby on rails 如何在使用jquery file upload将原始文件直接上载到s3后使用carrierwave创建缩略图,ruby-on-rails,ruby,ruby-on-rails-3,carrierwave,Ruby On Rails,Ruby,Ruby On Rails 3,Carrierwave,我通过jquery_文件上传图像(Railscast第383集) 上传效果很好,我在回调函数中得到了url 问题是:我想在直接上传到s3之后创建一些缩略图 为此,我假设: 服务器必须从s3读取映像 服务器必须创建缩略图 服务器必须将缩略图直接存储在s3中 服务器必须得到回调并相应地显示缩略图 服务器必须存储创建的缩略图的字段 现在,在映像完成后,上载映像控制器回调调用: def create #get the url from the callbcack #e.g: image[image_
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
def创建
#从callbcack获取url
#e、 g:图像[图像源]=https://.s3.amazonaws.com/uploads/myimage.png
@image=image.new(参数[:image])
@image.user\u id=当前用户id
@image.save
结束
模型:
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
类映像
上传后是否需要创建缩略图?如果没有,我认为您可以使用version
在初始上传期间创建缩略图(或任意大小)。例如:
class ImageUploader < CarrierWave::Uploader::Base
version :thumb do
process :resize_to_fill => [50, 50]
end
end
class ImageUploader[50,50]
结束
结束
你有没有得到过这个问题的答案?