簡體   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