Ruby on rails 使用S3在Heroku上上传回形针

Ruby on rails 使用S3在Heroku上上传回形针,ruby-on-rails,ruby,heroku,amazon-s3,paperclip,Ruby On Rails,Ruby,Heroku,Amazon S3,Paperclip,我很抱歉再次发牢骚,但我已经不知所措,不知道下一步该怎么办。我在Heroku上使用回形针,并配置了S3上传。我能够在本地开发环境中工作,但在Heroku上运行后,我遇到了以下错误: AWS::S3::Errors::PermanentRedirect (The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to

我很抱歉再次发牢骚,但我已经不知所措,不知道下一步该怎么办。我在Heroku上使用回形针,并配置了S3上传。我能够在本地开发环境中工作,但在Heroku上运行后,我遇到了以下错误:

AWS::S3::Errors::PermanentRedirect (The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.
我已经在谷歌上搜索了这个错误,并通读了Heroku文档,我相信我已经正确地设置了一切。我最初认为我的问题源于我的桶在
s3-us-west-1.amazonaws.com
地区,但我不再相信了

以下是我的Heroku配置的相关部分:

AWS_REGION:                      us-west-1
S3_BUCKET_NAME:                  my-super-awesomely-amazing-bucket
从我的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']
    } 
  }
My paperclip.rb初始化文件:

if Rails.env.production? 
  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-us-west-1.amazonaws.com'
end
以及相关型号的回形针配置:

has_attached_file :document,
:styles => { },
:default_url => "/image_styles/:style/missing.png"

那么…我做错了什么?在这一点上,我肯定我错过了一些明显的东西,但我很难从这里开始。我觉得我已经刻苦地配置了所有东西,但是
direct
错误不断出现

试试这个链接。以前,这种情况仅发生在欧洲地区,通过设置
AWS::S3::DEFAULT\u HOST
可以解决。希望这能解决你的问题

这可能不是直接的解决方案,但我们发现您必须在
s3\u凭证
块之外包含
bucket
选项:

#config/environments/production.rb
config.paperclip_defaults = {
    storage: :s3,
    s3_host_name: 's3-eu-west-1.amazonaws.com',
    s3_credentials: {
      access_key_id: ENV['AWS_ACCESS_KEY_ID'],
      secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
    },
    bucket: ENV['S3_BUCKET_NAME']
}
这在Heroku上对我们是100%有效的,但它是否对您有效(因为您的桶位于不同的区域)则是另一回事


如果您需要更多帮助,请发表评论,我将很乐意为您提供一些想法

谢谢您的回答-事实证明这是完全不同的。我的问题是我在北卡利地区创造了一个水桶。别问我为什么,这就是问题所在。当我把它换成俄勒冈州制造的水桶时,一切都开始运转了。很奇怪。