Roh*_*mar 8 ruby ruby-on-rails image-uploading ruby-on-rails-3 carrierwave
我使用带有RMagic的carrierwave 0.10.0 gem来在AWS S3上上传图像.一切都运行正常,除了花费太多时间在AWS S3上传.所以想到使用carrierwave背景来在背景中上传图像.我设置了载波波浪背景(0.4.2),但在这一个我的原始文件总是上传到S3,但该图像的版本永远不会上传到S3.
这是我的carrierwave_backgrounder.rb
CarrierWave::Backgrounder.configure do |c|
c.backend :sidekiq, queue: :carrierwave
end
Run Code Online (Sandbox Code Playgroud)
我在sidekiq.rb中定义了我的队列
Sidekiq.configure_server do |config|
config.redis = { :url => "redis://#{ENV['REDIS_ENDPOINT']}:6379", :namespace=> "#{ENV['REDIS_NAMESPACE']}" }
config.options =
queues: %w{
critical
carrierwave
}
})
end
Run Code Online (Sandbox Code Playgroud)
这是我的photo_uploader.rb
class PhotoUploader < CarrierWave::Uploader::Base
include ::CarrierWave::Backgrounder::Delay
include CarrierWave::RMagick
storage :fog
def store_dir
"uploads/images/"
end
def filename
"#{secure_token}.#{file.extension}" if original_filename.present?
end
def orient_image
manipulate! do |img|
img.auto_orient
img
end
end
# Create different versions of your uploaded files:
version :thumb_small do
process :resize_to_fill => [100,100]
process :strip
end
def strip
manipulate! do |img|
img.strip!
img = yield(img) if block_given?
img
end
end
def extension_white_list
%w(jpg jpeg gif png)
end
def get_version_dimensions
model.width, model.height = `identify -format "%wx%h " #{file.path}`.split(/x/)
end
protected
def secure_token
var = :"@#{mounted_as}_secure_token"
model.instance_variable_get(var) || model.instance_variable_set(var, SecureRandom.hex(5))
end
end
Run Code Online (Sandbox Code Playgroud)
这是我的profile.rb文件
mount_uploader :image_url, PhotoUploader
process_in_background :image_url
Run Code Online (Sandbox Code Playgroud)
我已经使用此命令启动了sidekiq worker
bundle exec sidekiq -d -L log/sidekiq.log -C config/sidekiq.yml -e development
Run Code Online (Sandbox Code Playgroud)
当我上传image_url时,仅上传原始图像.这是上传原始文件后的sidekiq日志.但我没有看到上传任何版本文件.我也查了S3桶(没有版本文件只有原始文件)
2016-01-11T08:52:20.772Z 3983 TID-ownpyrrxk CarrierWave::Workers::ProcessAsset JID-91e3803d50defb2d1419cef1 INFO: start
2016-01-11T08:52:31.119Z 3983 TID-ownpyrrxk CarrierWave::Workers::ProcessAsset JID-91e3803d50defb2d1419cef1 INFO: done: 10.347 sec
Run Code Online (Sandbox Code Playgroud)
有什么我想念的东西.请提前帮助谢谢
在调查了一些文件后,这是我的建议:
来自 Careerwave_backgrounder 自述文件:https://github.com/lardawge/rierwave_backgrounder#background-options
它清楚地表明,
# This stores the original file with no processing/versioning.
# It will upload the original file to s3.
Run Code Online (Sandbox Code Playgroud)
从这个#113,作者说
I found a bug related to Rmagick but no issue with versions
Run Code Online (Sandbox Code Playgroud)
您可以尝试使用 MiniMagick/ImageMagick 而不是 RMagick。
查找类似问题的文档:
https://github.com/lardawge/rierwave_backgrounder/issues/113
https://github.com/lardawge/rierwave_backgrounder/issues/130
由于某种原因未创建 Rails CarrierWave 版本
谢谢!