我正在使用carrierwave_backgrounder在使用 Sidekiq 的后台进程中将图像上传到 S3。
这是我的background_uploader.rb类...
class BackgroundUploader < CarrierWave::Uploader::Base
include ::CarrierWave::Backgrounder::Delay
include CarrierWave::RMagick
include CarrierWave::MimeTypes
process :set_content_type
# Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
include Sprockets::Helpers::RailsHelper
include Sprockets::Helpers::IsolatedHelper
storage :fog
def store_dir
"uploads/backgrounds/#{model.id}"
end
def default_url
"/assets/default.jpg"
end
process :resize_to_fit => [1024, 1024]
process :convert => 'jpg'
process :fix_exif_rotation
def extension_white_list
%w(jpg jpeg png)
end
def filename
@name ||= Digest::MD5.hexdigest(File.dirname(current_path.to_s))
"#{@name}.#{file.extension}" if original_filename
end
# Rotates the image based on the EXIF Orientation & applies gaussian blur
def fix_exif_rotation
manipulate! do |img|
img.auto_orient!
img = yield(img) if block_given?
img = img.gaussian_blur(0.0, 20.0)
img
end
end
end
carrierwave_backgrounder.rb:
CarrierWave::Backgrounder.configure do |c|
c.backend :sidekiq, queue: :carrierwave
end
background.rb包含:
mount_uploader :image, BackgroundUploader
process_in_background :image
然后我跑去sidekiq -q carrierwave
启动后台工作人员。一切正常!上传文件,我看到队列接受它并开始工作......
如果我立即打开我的 AWS S3 控制台,我会在其中看到原始文件。未调整大小且未模糊。工作完成后...我刷新 S3 并且有调整大小/模糊的版本。现在两个图像都在那里,但我只希望模糊图像在那里。在我看来,我使用...
<%= image_tag(@background.image.to_s) %>
它显示原始文件。如果我选中复选框以删除文件,它应该会这样做(从 S3 中删除原始文件),但模糊版本会保留在那里。
上传到 S3 的内容...
- original.jpg (立即......我根本不想上传这个)
- modified.jpg(作业完成后)
长话短说:我不希望将原始文件上传到 S3。