我有Carrierwave上传图片蛮好S3桶。但是,如果我用RMagick来处理缩略图,该文件只被保存到公共TMP本地。注释掉工艺方法创建S3的原件和拇指的文件(当然拇指不处理)。不知道为什么在处理写入本地TMP后停靠。低于code:
I have Carrierwave uploading images just fine to S3 buckets. However if I use RMagick to process thumbnails, the files only get saved to public tmp locally. Commenting out the process method creates the original and thumb files on S3 (of course the thumb is not processed). Not sure why the processing is stopping right after writing to local tmp. Code below:
class FileUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
storage :fog
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
# Create different versions of your uploaded files:
version :thumb do
process :resize_to_fit => [32, 32]
end
end
的Rails 3.2.5 雾1.3.1 Rmagick 2.13.1 Carrierwave 0.6.2 Carrierwave-mongoid 0.2.1
Rails 3.2.5 Fog 1.3.1 Rmagick 2.13.1 Carrierwave 0.6.2 Carrierwave-mongoid 0.2.1
我建议你使用minimagick:
I recommend you use minimagick:
class FileUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
end
有关拇指的版本,我建议你,你使用 resize_to_fill
喜欢某事的方法:
For thumb version I recommend you that you use resize_to_fill
method like sth:
version :thumb do
process :resize_to_fill => [32, 32]
process :convert => :png
end
您也可以使用一个独特的标记为每个图像:
you can also use a unique token for each image:
def filename
@name ||= "#{secure_token}.#{file.extension}" if original_filename.present?
end
protected
def secure_token
var = :"@#{mounted_as}_secure_token"
model.instance_variable_get(var) or model.instance_variable_set(var, SecureRandom.uuid)
end
您必须确保你的水桶你的连接是在秘密文件中正确配置/初始化/ fog.rb
某事,如:
you must ensure that your connection with your bucket is correct in the confidential file config/initializers/fog.rb
sth like:
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => 'your_key',
:aws_secret_access_key => 'your_secret_key',
:region => 'us-east-1'
}
config.fog_directory = 'your_bucket_here'
config.fog_public = true
config.fog_attributes = {'Cache-Control' => 'max-age=315576000'}
end