简体   繁体   English

上载文件时出现AWS / Heroku错误

[英]AWS/Heroku Errors out when uploading files

So, I have a rails/react application that is currently deployed to Heroku. 因此,我有一个Rails / React应用程序,当前已部署到Heroku。 Everything works minus the uploading feature. 一切正常,减去上传功能。 I switched over from local storage to AWS (CarrierWave/Fog) but it errors out when the PUT request is sent for uploading. 我从本地存储切换到AWS(CarrierWave / Fog),但在发送PUT请求进行上传时却出错。 Here is what I have... 这就是我所拥有的...

2017-07-26T00:15:26.403722+00:00 app[web.1]: [d2e717f7-5bc0-4832-a441-0f382dffc6c7]    (3.9ms)  BEGIN
2017-07-26T00:15:26.409753+00:00 app[web.1]: [d2e717f7-5bc0-4832-a441-0f382dffc6c7]   SQL (3.3ms)  INSERT INTO "photos" ("user_id", "created_at", "updated_at", "photos") VALUES ($1, $2, $3, $4) RETURNING "id"  [["user_id", 4], ["created_at", "2017-07-26 00:15:26.404361"], ["updated_at", "2017-07-26 00:15:26.404361"], ["photos", "[\"15740973_10211933753000319_7147015776553812508_n.jpg\"]"]]
2017-07-26T00:15:27.103871+00:00 heroku[router]: at=info method=POST path="/photos" host=www.--MY-DOMAIN-NAME--.com request_id=d2e717f7-5bc0-4832-a441-0f382dffc6c7 fwd="76.118.245.207" dyno=web.1 connect=1ms service=3593ms status=500 bytes=1827 protocol=http
2017-07-26T00:15:27.099506+00:00 app[web.1]: [d2e717f7-5bc0-4832-a441-0f382dffc6c7]    (5.3ms)  ROLLBACK
2017-07-26T00:15:27.100107+00:00 app[web.1]: [d2e717f7-5bc0-4832-a441-0f382dffc6c7] Completed 500 Internal Server Error in 3404ms (ActiveRecord: 13.3ms)
2017-07-26T00:15:27.101564+00:00 app[web.1]: [d2e717f7-5bc0-4832-a441-0f382dffc6c7]
2017-07-26T00:15:27.101609+00:00 app[web.1]: [d2e717f7-5bc0-4832-a441-0f382dffc6c7] Excon::Error::Forbidden (Expected(200) <=> Actual(403 Forbidden)
2017-07-26T00:15:27.101611+00:00 app[web.1]: excon.error.response
2017-07-26T00:15:27.101625+00:00 app[web.1]:   :body          => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>70D9E2369BE5D8A0</RequestId><HostId>qFX1z2eqsP+/Mt9j+uompGs2Z4RRfNDb1ZqMJ6Bfs+ijY8oUEI56XLXeM8kAoWvK276DauKGRYg=</HostId></Error>"
2017-07-26T00:15:27.101626+00:00 app[web.1]:   :cookies       => [
2017-07-26T00:15:27.101627+00:00 app[web.1]:   ]
2017-07-26T00:15:27.101628+00:00 app[web.1]:   :headers       => {
2017-07-26T00:15:27.101629+00:00 app[web.1]:     "Connection"       => "close"
2017-07-26T00:15:27.101630+00:00 app[web.1]:     "Content-Type"     => "application/xml"
2017-07-26T00:15:27.101631+00:00 app[web.1]:     "Date"             => "Wed, 26 Jul 2017 00:15:26 GMT"
2017-07-26T00:15:27.101632+00:00 app[web.1]:     "x-amz-id-2"       => "qFX1z2eqsP+/Mt9j+uompGs2Z4RRfNDb1ZqMJ6Bfs+ijY8oUEI56XLXeM8kAoWvK276DauKGRYg="
2017-07-26T00:15:27.101634+00:00 app[web.1]:   }
2017-07-26T00:15:27.101631+00:00 app[web.1]:     "Server"           => "AmazonS3"
2017-07-26T00:15:27.101633+00:00 app[web.1]:     "x-amz-request-id" => "70D9E2369BE5D8A0"
2017-07-26T00:15:27.101635+00:00 app[web.1]:   :host          => "MY-BUCKET-NAME-production.s3-us-east-2.amazonaws.com"
2017-07-26T00:15:27.101636+00:00 app[web.1]:   :local_address => "172.16.75.138"
2017-07-26T00:15:27.101636+00:00 app[web.1]:   :local_port    => 50501
2017-07-26T00:15:27.101637+00:00 app[web.1]:   :path          => "/uploads/photo/photos/20/15740973_10211933753000319_7147015776553812508_n.jpg"
2017-07-26T00:15:27.101638+00:00 app[web.1]:   :port          => 443
2017-07-26T00:15:27.101638+00:00 app[web.1]:   :reason_phrase => "Forbidden"
2017-07-26T00:15:27.101639+00:00 app[web.1]:   :remote_ip     => "52.219.80.56"
2017-07-26T00:15:27.101640+00:00 app[web.1]:   :status        => 403
2017-07-26T00:15:27.101640+00:00 app[web.1]:   :status_line   => "HTTP/1.1 403 Forbidden\r\n"
2017-07-26T00:15:27.101641+00:00 app[web.1]: ):
2017-07-26T00:15:27.101673+00:00 app[web.1]: [d2e717f7-5bc0-4832-a441-0f382dffc6c7]
2017-07-26T00:15:27.101718+00:00 app[web.1]: [d2e717f7-5bc0-4832-a441-0f382dffc6c7] app/controllers/photos_controller.rb:36:in `create'

.env file

AWS_ACCESS_KEY_ID     = Retracted
AWS_SECRET_ACCESS_KEY = Retracted
S3_BUCKET             = Retracted

carrierwave.rb file. carrierwave.rb文件。 Located in config/initializers/carrierwave.rb 位于config/initializers/carrierwave.rb

require 'carrierwave/orm/activerecord'

CarrierWave.configure do |config|
  if !Rails.env.test?
    config.fog_credentials = {
      provider: "AWS",
      aws_access_key_id: ENV["AWS_ACCESS_KEY_ID"],
      aws_secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"],
      :region => 'us-east-2'
    }
    config.fog_directory  = ENV["S3_BUCKET"]
  end
end

My Uploader file, photos_uploader.rb 我的上载器文件photos_uploader.rb

class PhotosUploader < CarrierWave::Uploader::Base

  ...

  # Choose what kind of storage to use for this uploader:
    if Rails.env.test?
      storage :file
    else
      storage :fog
    end

  ...

I have used this method on a previous project and had no issues. 我在以前的项目中使用过这种方法,没有任何问题。 The only different between the two is that on the other one I used the built in Heroku Domain name. 两者之间的唯一区别在于,另一个是我使用内置的Heroku域名。 On this one, I purchased my own domain name and set it up so the DNS pointed to Heroku. 在此服务器上,我购买了自己的域名并进行了设置,以便DNS指向Heroku。 I am thinking, possibly that is messing things up, but I am out of ideas at this point. 我在想,可能是把事情弄糟了,但是在这一点上,我没有想法。

Running, heroku run rails c and then Photo.all confirms that nothing is saved to the database. 运行时, heroku run rails c ,然后Photo.all确认没有任何内容保存到数据库。

So, a little embarrassed here. 所以,这里有些尴尬。 Always check for spelling... 经常检查拼写...

The permission I had on my user was AmazonSESFullAccess 我对用户的权限是AmazonSESFullAccess

Which, of course is a lot different that what I wanted - AmazonS3FullAccess 当然,这与我想要的有很大不同AmazonS3FullAccess

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

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