我尝试使用 paperclip 和 Amazon s3。我的存储桶位于欧盟的(爱尔兰),但我遇到了以下错误:
AWS::S3::Errors::PermanentRedirect in MyControllerController
The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.
这很烦人,我试图修复它,但我觉得我会死在不断尝试中。
所以这是我的代码:
s3.yml
access_key_id: *****
secret_access_key: ****
bucket: mybucketname
AWS_CALLING_FORMAT: s3-eu-west-1-amazonaws.com #not sure for this one
我10分钟前尝试了最后一次测试的调用格式,但没有任何变化。
config/initializers/paperclip.rb
Paperclip.options[:command_path] = "/usr/local/bin/"
Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename'
Paperclip::Attachment.default_options[:s3_host_name] = 's3-eu-west-1-amazonaws.com'
因此,我的模型:
has_attached_file :attachment,
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:path => "pictures/:id/:style.:extension",
:bucket => 'mybucketname'
最后
# in config/initializers/something.rb
Paperclip.interpolates(:s3_eu_url) { |assets, style|
"#{assets.s3_protocol}://s3-eu-west-1.amazonaws.com/#{assets.recipesappdev} /#{assets.path(style).gsub(%r{^/}, "")}"
}
如果我忘记在这里放置文件,请告诉我。
有人有想法吗?
谢谢
编辑: 现在我遇到了这个错误:
getaddrinfo: nodename nor servname provided, or not known
...真的毫无头绪