繁体   English   中英

如何在使用jquery文件上传将原始文件直接上传到s3后使用carrierwave创建缩略图

[英]How to create thumbnails with carrierwave after uploading the original file directly to s3 with jquery file upload

我通过jquery_file_upload上传图片(Railscast第#383集)上传工作完美,我在回调函数中获取了url

问题是:我想在直接上传到s3后创建一些缩略图

为此我假设:

  1. 服务器必须从s3读取图像
  2. 服务器必须创建缩略图
  3. 服务器必须直接在s3中存储缩略图
  4. 服务器必须得到回调并相应地显示缩略图。
  5. 服务器必须存储缩略图创建的字段

现在,在图像完成后上传图像控制器回调调用:

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

而型号:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM