我遵循了Carrierwave的部署说明,了解如何使用Amazon S3在Heroku上部署Rails应用程序:
https://github.com/carrierwaveuploader/carrierwave/wiki/How-to%3A-Make-Carrierwave-work-on-Heroku
我已将额外的行添加到config.ru并创建了config / initializers / carrierwave.rb文件,但没有成功。
下面是carrierwave初始化程序,其中包含密钥。
这是否正确设置?
我还需要做什么?
任何分步指南都可以帮助我实现这个目标吗?
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => REDACTED, # required
:aws_secret_access_key => REDACTED, # required
:region => 'eu-west-1', # optional, defaults to 'us-east-1'
:host => 's3.example.com', # optional, defaults to nil
:endpoint => 'https://s3.example.com:8080' # optional, defaults to nil
}
config.fog_directory = 'myawsbucket' # required
config.fog_public = false # optional, defaults to true
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'} # optional, defaults to {}
end
答案 0 :(得分:7)
您是否生成了上传者文件?
rails generate uploader Avatar
这将生成如下文件: 应用程序/上传/ avatar_uploader.rb class AvatarUploader< CarrierWave ::上传::基地 存储:文件 端
“使用入门”中的更多信息https://github.com/carrierwaveuploader/carrierwave。
这是我的档案 配置/初始化/ carrierwave.rb
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => 'REDACTED',
:aws_secret_access_key => 'REDACTED'
}
config.fog_directory = "myawsbucket"
end
应用程序/上传/ amazon_uploader.rb
class AmazonUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
include Sprockets::Helpers::RailsHelper
include Sprockets::Helpers::IsolatedHelper
storage :fog
include CarrierWave::MimeTypes
process :set_content_type
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :user_thumb do
process :resize_to_limit => [200, 200]
end
def extension_white_list
%w(jpg jpeg gif png)
end
end
我也推荐你这个铁路广播: