[英]Rails 4, Carrierwave-aws, images uploaded to Amazon s3 locally, but not in production (Openshift)
I have a Rails 4 application hosted on openshift. 我在openshift上托管了Rails 4应用程序。 I am using carrierwave and the carrierwave-aws gem to handle image upload.
我正在使用carrierwave和carrierwave-aws gem处理图像上传。 When I test it locally, the images are uploaded and displayed as expected to Amazon S3.
当我在本地对其进行测试时,图像将按预期上传并显示到Amazon S3。 However, on production server, which is hosted on Openshift, the images are uploaded to '/uploads/images' instead of Amazon.
但是,在Openshift托管的生产服务器上,图像会上传到“ / uploads / images”而不是Amazon。 Here are my configurations and Gemfile:
这是我的配置和Gemfile:
gem 'carrierwave'
gem 'carrierwave-aws'
In initializers/carrierwave.rb 在initializers / carrierwave.rb中
#config/initializers/carrierwave.rb
CarrierWave.configure do |config|
config.storage = :aws
config.aws_bucket = 'mybucketname'
config.aws_acl = :public_read
config.asset_host = 'https://mybucketname.s3-us-west-1.amazonaws.com'
config.aws_authenticated_url_expiration = 60 * 60 * 24 * 365
config.aws_credentials = {
# Configuration for Amazon S3
:provider => 'AWS',
:access_key_id => 'myaccessid',
:secret_access_key => 'mysecretkey',
:region => 'us-west-1',
}
config.storage = :aws
config.cache_dir = "#{Rails.root}/tmp/uploads"
end
In image_uploader.rb I also put 在image_uploader.rb中,我还放了
storage :aws
Just in case this helps: I used Fog before and locally it also works fine. 以防万一这有帮助:我以前使用过Fog,在本地也可以正常使用。 However on production it gives an Excon error.
但是在生产中会出现Excon错误。 After some googling I come to the conclusion that carrierwave-aws is a better choice.
经过一番谷歌搜索后,我得出的结论是,载波电波是更好的选择。
use gem 'fog' and gem 'carrierwave' use this snippet 使用宝石“雾”和宝石“载波”使用此代码段
CarrierWave.configure do|config|
config.fog_credentials = {
provider: 'AWS',
aws_access_key_id: 'AWS_ACCESS_KEY',
aws_secret_access_key: 'AWS_SECRET_KEY',
region: 'region-name',
host: 's3.example.com',
endpoint: 'https://s3.example.com'
}
config.fog_directory = 'name of the bucket'
config.fog_public = 'false'
config.fog_attributes = {'Cache-Control' => "max-age=#{365.to_i}" }
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.