2
我已經配置了Carrierwave + Fog以與Amazon S3配合使用。我遇到的問題是,所有內容都是在我的項目的公用文件夾中創建的,並未上傳到S3。拇指和目錄是可以的,只是沒有工作的圖像的位置。Carrierwave本地上傳圖像,而不是S3
我上傳:
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :fog
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :thumb do
process :resize_to_fit => [200, 200]
end
def extension_white_list
%w(jpg jpeg gif png)
end
end
fog.rb
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => 'xxx',
:aws_secret_access_key => 'yyy',
:region => 'eu-west-1'
}
config.fog_directory = 'your_bucket_here'
config.fog_public = true
config.fog_attributes = {'Cache-Control' => 'max-age=315576000'}
end
使用類是:
class Image < ActiveRecord::Base
belongs_to :product
mount_uploader :remote_file, ImageUploader
end
而控制器代碼:
i = Image.new
i.save
i.remote_file = params[:image]
render :json => {:response => i.remote_file.url}
的迴應是: { 「迴應」: 「/上傳的/ tmp/1387464252-27678-6793/logo11w.png」}
和Rails項目的公共目錄中創建映像。
謝謝!
工作正常!謝謝! –