我一直在railstutorial.org上关注rails 4教程。我完成了大部分工作,该项目托管在heroku上,但现在想要将镜像上传到Amazon S3。我已经按照heroku网站上的指南进行了操作,但在S3(欧洲)上无法上传任何内容到我的存储桶中。rails 4回形针上传到亚马逊s3不起作用
我正在使用回形针3.5.2。
Post模型
has_attached_file :post_photo,
styles: {
thumb: '100x100>',
square: '200x200#',
medium: '300x300>'
},
:storage => :s3,
:s3_credentials => {
:access_key_id => ENV['S3_KEY'],
:secret_access_key => ENV['S3_SECRET'] },
:s3_protocol => "https",
:path => ":class/:id/:basename_:style.:extension",
:url => ':s3_eu_url',
:bucket => 'bucket_name'
柱控制器
def post_params
params.require(:post).permit(:post_photo, :user_username, :title, :comment, :location, :user_id)
end
配置/初始化/ Paperclip.rb
Paperclip.interpolates(:s3_eu_url) { |attachment, style|
"#{attachment.s3_protocol}://s3-eu-west-1.amazonaws.com/#{attachment.bucket_name}/#{attachment.path(style).gsub(%r{^/}, "")}"
}
到config/environment.rb
require 'aws/s3'
AWS::S3::DEFAULT_HOST = "s3-eu-west-1.amazonaws.com"
配置/环境/ production.rb
# config/environments/production.rb
config.paperclip_defaults = {
:storage => :s3,
:s3_credentials => {
:bucket => ENV['S3_BUCKET_NAME'],
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
},
:url => ':s3_eu_url',
:path => ":class/:id/:basename_:style.:extension"
}
你使用的是'aws-sdk'吗? –