0

Carrierwave が S3 バケットに問題なく画像をアップロードしています。ただし、RMagick を使用してサムネイルを処理すると、ファイルはローカルのパブリック tmp にのみ保存されます。process メソッドをコメントアウトすると、S3 に元のファイルとサム ファイルが作成されます (もちろん、サムは処理されません)。ローカル tmp への書き込み直後に処理が停止する理由がわかりません。以下のコード:

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 Fog 1.3.1 Rmagick 2.13.1 Carrierwave 0.6.2 Carrierwave-mongoid 0.2.1

4

1 に答える 1

0

minimagickを使用することをお勧めします。

class FileUploader < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick
end

resize_to_fillサムバージョンの場合、 sthのような方法を使用することをお勧めします。

version :thumb do
   process :resize_to_fill => [32, 32]
   process :convert => :png
 end

画像ごとに一意のトークンを使用することもできます。

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

config/initializers/fog.rb次のような機密ファイルで、バケットとの接続が正しいことを確認する必要があります。

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
于 2012-06-17T11:37:13.167 に答える