所以,我有一个当前部署到Heroku的rails / react应用程序。一切都有效减去上传功能。我从本地存储切换到AWS(CarrierWave / Fog),但在发送PUT请求进行上传时出错。这就是我的......
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
档案。位于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
我的上传器文件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
...
我在之前的项目中使用过这种方法并且没有任何问题。两者之间唯一不同的是,另一方面我使用了内置的Heroku域名。在这个,我购买了自己的域名并进行了设置,因此DNS指向了Heroku。我在想,可能是搞砸了,但我现在已经没想到了。
正在运行,heroku run rails c
然后Photo.all
确认没有任何内容保存到数据库中。
答案 0 :(得分:0)
所以,这里有点尴尬。总是检查拼写...
我对用户的权限是AmazonSESFullAccess
当然,与我想要的内容有很大不同 - AmazonS3FullAccess