简体   繁体   English

使用Paperclip部署到Heroku上载文件时,AWS Endpoint错误

[英]AWS Endpoint Error When Uploading Files Using Paperclip Deploying to Heroku

When I upload an image using Paperclip on Heroku, it uploads the image as http://s3.amazonaws.com/moviereviewnd/movies/images/000/000/005/small/wolf_of_wall_street_ver3_xxlg.jpeg?1424809711 当我在Heroku上使用回形针上传图像时,它以http://s3.amazonaws.com/moviereviewnd/movies/images/000/000/005/small/wolf_of_wall_street_ver3_xxlg.jpeg?1424809711上传图像

Note: It uploads fine on local server (Ubuntu 14.04). 注意:它可以在本地服务器(Ubuntu 14.04)上正常上传。 I've tried everything I can find on this site and nothing seems to work. 我已经尽力在此站点上可以找到的所有内容,但似乎无济于事。 The Bucket is definitely not a Eurpoean bucket or anything like that. “ Bucket”绝对不是“ Eurpoean”之类的东西。 I chose Oregon and when I log into AWS, it says https://console.aws.amazon.com/s3/home ? 我选择了俄勒冈州,当我登录AWS时,它显示为https://console.aws.amazon.com/s3/home region=us-west-2 地区= US-西2

When you visit the image URL posted above, it says "The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.". 当您访问上面发布的图像URL时,它会显示“您尝试访问的存储桶必须使用指定的端点进行寻址。请将所有以后的请求发送到该端点。” It also says when you visit the above URL that the endpoint is: 它还表示,当您访问上述URL时,端点为:

moviereviewnd.s3.amazonaws.com moviereviewnd.s3.amazonaws.com

Any ideas? 有任何想法吗? I've been stuck on this for hours and cannot seem to figure it out. 我已经坚持了几个小时,似乎无法弄清楚。

In my config/environments/production.rb, I currently have this: 在我的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'],
  :region => 'us-west-2',
  :s3_endpoint => 's3-us-west-2.amazonaws.com'
}
}

But have also tried this: 但是也尝试过这个:

  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'],
  :region => 'us-west-2',
  :s3_endpoint => 'moviereviewnd.s3.amazonaws.com'
}
}

Both ways result in the same URL mentioned at the top of this post and lead to the "must be addressed using the specified endpoint" message. 两种方法都导致本文开头提到的URL相同,并导致“必须使用指定的端点进行寻址”消息。

Here is my Gemfile: 这是我的Gemfile:

source 'https://rubygems.org'
gem 'rails',                '4.2.0'
gem 'sass-rails',           '5.0.1'
gem 'uglifier',             '2.5.3'
gem 'coffee-rails',         '4.1.0'
gem 'jquery-rails',         '4.0.3'
gem 'turbolinks',           '2.3.0'
gem 'jbuilder',             '2.2.3'
gem 'sdoc',                 '0.4.0', group: :doc
gem 'devise', '~> 3.4.1'
gem 'paperclip', '~> 4.2.1'
gem 'aws-sdk', '< 2.0'
gem 'bootstrap-sass', '~> 3.3.3'
gem 'rmagick', '~> 2.13.4'

group :development, :test do
  gem 'sqlite3',     '1.3.9'
  gem 'byebug',      '3.4.0'
  gem 'web-console', '2.0.0.beta3'
  gem 'spring',      '1.1.3'
end

group :production do
  gem 'pg',             '0.17.1'
  gem 'rails_12factor', '0.0.2'
end

Woohoo! 哇噢! Using :s3_host_name instead of :s3_endpoint worked! 使用:s3_host_name代替:s3_endpoint是可行的!

  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'],
      :region => 'us-west-2',
      :s3_host_name => 's3-us-west-2.amazonaws.com',
      :url => ":s3_domain_url"
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM