在生成的图像网址中,缺少区域名称。我可以存储但不能检索图像。
例如存储在
的图像https://s3-ap-southeast-2.amazonaws.com/drill-investor-bucket/attachments/images/000/000/042/original/image-3.png
在应用程序中的视图
<%= image_tag attachment.image.url %> <br />
生成此地址
https://s3.amazonaws.com/drill-investor-bucket/attachments/images/000/000/042/original/image-3.png?1393281373
我尝试了许多不同的方法来尝试将区域放入视图地址。在下面的代码中,存在一些失败尝试,但已注释掉。
在config / initializes / paperclip.rb
中#Paperclip::Attachment.default_options[:host] = 's3-ap-southeast-2.amazonaws.com'
Paperclip::Attachment.default_options[:storage] = :s3
# Paperclip::Attachment.default_options[:s3_endpoint] = 's3-ap-southeast-2.amazonaws.com'
# Paperclip::Attachment.default_options[:region] = 'ap-southeast-2'
Paperclip::Attachment.default_options[:s3_protocol] = 'https'
Paperclip::Attachment.default_options[:s3_credentials] =
{ :bucket => ENV['AWS_BUCKET'],
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'] }
# https://s3-ap-southeast-2.amazonaws.com/drill-investor-bucket/attachments
# /images/000/000/042/original/image-3.png
#Paperclip::Attachment.default_options[:host] = 's3-ap-southeast-2.amazonaws.com' #module AWS
# module S3
# DEFAULT_HOST = "s3.amazonaws.com"
# end
#end
#AWS::S3::DEFAULT_HOST.replace "s3-ap-southeast-2.amazonaws.com"
图像附加到附件模型。该模型的相关部分如下。
....
has_attached_file :image,
:s3_credentials => {
access_key_id: 'my boss would probably',
secret_access_key: 'object if I left the actual id and key info here',
# region: 'ap-southeast-2',
bucket: 'drill-investor-bucket'
# s3_endpoint: 's3-eu-west-1.amazonaws.com'
}
....
来自Gemfile
ruby '2.0.0'
gem 'rails', '4.0.0'
...
gem 'paperclip' , '~> 4.1.0'
gem 'aws-sdk'
任何帮助或建议都很高兴。
感谢 皮尔
答案 0 :(得分:1)
我遇到了另一个(认为我已经检查过所有)查询stackoverflow,它回答了这个问题。 使用他们的答案我添加到config / initializers / paperclip.rb
Paperclip::Attachment.default_options[:s3_host_name] = 's3-ap-southeast-2.amazonaws.com'
感谢stackoverflow上发布的那些帖子 Rails 4, Paperclip, Amazon S3 Config Amazon Path
皮尔