首页 文章

无法下载使用Paperclip(Rails)存储的s3图像

提问于
浏览
0

我可以使用Paperclip上传图像,并可以在亚马逊S3管理控制台网站上看到它们,但Paperclip提供的网址(例如,image.url(:thumb))不能用于访问图像 . 我得到一个看起来像这样的网址:

http://s3.amazonaws.com/xxx/xxx/images/000/000/012/thumb/image.jpg?1366900621

当我将该URL放入浏览器时,我被发送到一个XML页面,其中指出:“您尝试访问的存储区必须使用指定的 endpoints 进行寻址 . 请将所有将来的请求发送到此 endpoints . ”

其中“ endpoints ”是Paperclip路径的子域 . 但是当我进入那个“ endpoints ”时,我只是得到另一个错误,上面写着“拒绝访问” . 但是,根据亚马逊网站提供的文件信息,该图像是公开可见的 . 有人能告诉我我做错了什么吗?

我的development.rb文件只包含以下内容:

config.paperclip_defaults = {
    :storage => :s3,
    :s3_credentials => {
      :bucket => AWS_BUCKET,
      :access_key_id => AWS_ACCESS_KEY_ID,
      :secret_access_key => AWS_SECRET_ACCESS_KEY
    }
  }

1 回答

  • 2

    我通过更改默认值:url来实现它

    # config/initializers/paperclip.rb 
    Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
    Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename'
    

    我在美国本土,但似乎这仍然是我的代码工作所必需的(参见https://devcenter.heroku.com/articles/paperclip-s3

相关问题