一个月前,我将RoR-app上的Ruby版本从1.9.3升级到2.3.3。我已成功使用fog
& carrierwave
在此之前将图像上传到Amazon S3,但在升级之后它停止工作。它不会再将我的图像上传到S3,也不会在那里创建文件夹和文件。造成这种问题的原因是我根本无法排除故障,我没有收到任何错误消息或其他任何内容。
版本:
有用的信息:
初始化/ carrierwave.rb
CarrierWave.configure do |config|
config.storage = 'fog'
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => 'ABC123CODE',
:aws_secret_access_key => '+ABC123CODEKEY',
:region => 'eu-central-1'
}
config.fog_directory = 'myapp-se'
config.cache_dir = "#{Rails.root}/tmp"
config.fog_attributes = {
expires: 1.year.from_now.httpdate,
cache_control: "max-age=#{1.year.to_i}"
}
config.ignore_integrity_errors = false
config.ignore_processing_errors = false
config.ignore_download_errors = false
end
礼品型号(gift.rb) - (相关部分)
mount_uploader :cached_image, GiftImageUploader
#validates_integrity_of :cached_image
#validates_processing_of :cached_image
validates_integrity_of :cached_image
validates_processing_of :cached_image
validates_download_of :cached_image
file = Tempfile.new(["image", ".jpg"])
file.binmode
begin
open(URI.parse(external_image_url), :allow_redirections => :safe) do |data|
file.write data.read
end
rescue Exception => e
logger.info "Error fetching image for product #{id}: " + e.message
return false
end
file.rewind
self.cached_image = file
begin
self.skip_callbacks = true
if self.save!
logger.info "Successfully cached image for product #{id}"
return true
else
logger.info "Soft Error saving product #{id}"
return false
end
self.skip_callbacks = false
rescue Exception => e
logger.info "Rescue Error saving product #{id}" + e.message
end
上传者文件
class GiftImageUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
storage :fog
def store_dir
"cached/gifts/#{model.id}"
end
def extension_white_list
%w(jpg jpeg gif png)
end
version :s300 do
process resize_to_fit: [300, 300]
end
version :s200, :from_version => :s300 do
process resize_to_fit: [200, 200]
end
version :s150, :from_version => :s200 do
process resize_to_fit: [150, 150]
end
version :sq150 do
process resize_to_fill: [150, 150]
end
version :s75, :from_version => :s150 do
process resize_to_fit: [75, 75]
end
version :sq75 do
process resize_to_fill: [75, 75]
end
end
我需要帮助:
答案 0 :(得分:0)
您需要在启动应用程序之前运行bundle install
命令。如果它不起作用,请运行bundle update
,然后运行bundle install
。它应该有效,因为我过去也遇到过类似的问题。
答案 1 :(得分:0)
我使用carrierwave-aws gem解决了这个问题。对于未来的读者来说,解决方案过于复杂且过于具体,不适合我的特定应用。坦率地说,我不确定为什么这解决了这个问题。