我创建了一个运行在 Heroku 上的 Rails 应用程序,带有 Paperclip 和 S3。我已经设法通过站点将图像上传到我的 S3 存储桶(我可以看到它们显示在我的 Amazon 控制面板上的存储桶中)。
但是当我添加一个图像标签,即 <%= image_tag x.photo.url %> 时,我得到以下 html(这里省略了标签),没有显示图像!
img alt="Test_tree"src="http://s3.amazonaws.com/hiphotos/ads/photos/000/000/015/original/test_tree.jpg?1344661020"
请帮忙!为什么即使图像在存储桶中我也看不到它们?
非常感谢你们
最佳答案
创建一个名为 paperclip 初始值设定项的文件:
# config/initializers/paperclip.rb
# We are actually setting this to 's3_domain_url',
# so it's not a placeholder for something else.
Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename'
或者你也可以把它放在里面
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_domain_url',
:path => '/:class/:attachment/:id_partition/:style/:filename',
}
关于ruby-on-rails - Paperclip S3 - 可以上传图片但不能查看,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11912201/