简体   繁体   English

AWS / s3和回形针图像未保存

[英]AWS/s3 & Paperclip images not saving

I'm trying to use AWS & Paperclip for user uploads on my deployed app on Heroku, but I keep getting this error when I try to upload a post with an image attached to it: 我正在尝试使用AWS&Paperclip在Heroku上已部署的应用程序上进行用户上传,但是当我尝试上传附有图片的帖子时,我总是收到此错误消息:

** **

015-08-12T16:30:14.773630+00:00 app[web.1]: App 129 stdout: Started POST "/posts" for 24.52.240.16 at 2015-08-12 16:30:14 +0000
2015-08-12T16:30:14.956915+00:00 app[web.1]: App 113 stderr: sh: 1:
2015-08-12T16:30:14.999032+00:00 app[web.1]: App 113 stderr: sh: 1:
2015-08-12T16:30:15.701055+00:00 app[web.1]: App 113 stderr: sh: 1:
2015-08-12T16:30:15.664880+00:00 app[web.1]: App 129 stdout: Command :: PATH=C:\Program Files\ImageMagick-6.9.1-Q16:$PATH; identify -format %m '/tmp/e4b70d27eba59aa7021fe4c7a3f37f0920150812-129-lzw5hm.jpeg[0]'
2015-08-12T16:30:15.701148+00:00 app[web.1]: App 113 stderr: FilesImageMagick-6.9.1-Q16:/app/vendor/bundle/ruby/2.2.0/bin:/app/bin:/app/vendor/bundle/bin:/usr/local/bin:/usr/bin:/bin: not found
2015-08-12T16:30:15.701215+00:00 app[web.1]: App 113 stderr:
2015-08-12T16:30:15.668736+00:00 app[web.1]: App 113 stderr: sh: 1:
2015-08-12T16:30:15.668859+00:00 app[web.1]: App 113 stderr: FilesImageMagick-6.9.1-Q16:/app/vendor/bundle/ruby/2.2.0/bin:/app/bin:/app/vendor/bundle/bin:/usr/local/bin:/usr/bin:/bin: not found
2015-08-12T16:30:15.668921+00:00 app[web.1]: App 113 stderr:
2015-08-12T16:30:15.698923+00:00 app[web.1]: App 129 stdout: Command :: PATH=C:\Program Files\ImageMagick-6.9.1-Q16:$PATH; convert '/tmp/e4b70d27eba59aa7021fe4c7a3f37f0920150812-129-lzw5hm.jpeg[0]' -auto-orient -resize "300x300>" '/tmp/52d7f5bb59811ac88441c8968f792bbd20150812-129-1g4pubj'
2015-08-12T16:30:17.310929+00:00 app[web.1]: App 129 stdout: Command :: PATH=C:\Program Files\ImageMagick-6.9.1-Q16:$PATH; file -b --mime '/tmp/e4b70d27eba59aa7021fe4c7a3f37f0920150812-129-mnm95q.jpeg'
2015-08-12T16:30:17.314951+00:00 app[web.1]: App 113 stderr: sh: 1:
2015-08-12T16:30:17.315044+00:00 app[web.1]: App 113 stderr: FilesImageMagick-6.9.1-Q16:/app/vendor/bundle/ruby/2.2.0/bin:/app/bin:/app/vendor/bundle/bin:/usr/local/bin:/usr/bin:/bin: not found
2015-08-12T16:30:17.315109+00:00 app[web.1]: App 113 stderr:
2015-08-12T16:30:17.571944+00:00 app[web.1]: App 129 stdout: [paperclip] saving /posts/images/000/000/048/original/firefighters.jpeg
2015-08-12T16:30:17.947443+00:00 app[web.1]: App 129 stdout: [AWS S3 403 0.35544 0 retries] put_object(:acl=>:public_read,:bucket_name=>"apolloportalinc",:content_length=>2194514,:content_type=>"image/jpeg",:data=>Paperclip::UploadedFileAdapter: firefighters.jpeg,:key=>"posts/images/000/000/048/original/firefighters.jpeg") AWS::S3::Errors::AccessDenied Access Denied
2015-08-12T16:30:17.950079+00:00 app[web.1]: App 129 stdout: Completed 500 Internal Server Error in 3172ms
2015-08-12T16:30:17.947479+00:00 app[web.1]: App 129 stdout:
2015-08-12T16:30:17.966625+00:00 heroku[router]: at=info method=POST path="/posts" host=lit-dawn-3200.herokuapp.com request_id=ae1674d7-f249-4e40-b4cf-6228fbbf3f82 fwd="24.52.240.16" dyno=web.1 connect=1ms service=43027ms status=500 bytes=1829
2015-08-12T16:30:17.952777+00:00 app[web.1]: App 129 stdout:
2015-08-12T16:30:17.952841+00:00 app[web.1]: App 129 stdout:   app/controllers/posts_controller.rb:41:in `create'
2015-08-12T16:30:17.952818+00:00 app[web.1]: App 129 stdout: AWS::S3::Errors::AccessDenied (Access Denied):
2015-08-12T16:30:17.952884+00:00 app[web.1]: App 129 stdout:

** **

Here's what's in my paperclip.rb: 这是我的paperclip.rb中的内容:

require "paperclip"

Paperclip.options[:command_path] = 'C:\Program Files\ImageMagick-6.9.1-Q16'
Paperclip.options[:swallow_stderr] = false
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-2.amazonaws.com'

and I have the right code in my production.rb, according to this tutorial: https://devcenter.heroku.com/articles/paperclip-s3 根据此教程,在我的production.rb中有正确的代码: https : //devcenter.heroku.com/articles/paperclip-s3

  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']
  }
}

I honestly have no idea what I'm doing, so any help would be appreciated. 老实说,我不知道我在做什么,所以我们将不胜感激。

It sounds like from the error, you aren't authenticating with AWS on your heroku app. 听起来好像是错误,您没有在heroku应用程序上使用AWS进行身份验证。 That's most likely because you haven't set your ENV variables. 这很可能是因为您尚未设置ENV变量。 You need to run the following terminal commands. 您需要运行以下终端命令。

heroku config:set S3_BUCKET_NAME="thisisthenameofmybucket"
heroku config:set AWS_ACCESS_KEY_ID="myaccesskey"
heroku config:set AWS_SECRET_ACCESS_KEY="my_secret_access_key_here"

So you'll get all those values from AWS. 因此,您将从AWS获得所有这些值。 Then run those commands in the terminal and your ENV variables will be set. 然后在终端中运行这些命令,您的ENV变量将被设置。 That's kinda step one. 那是第一步。 Then you need to see what error comes after that. 然后,您需要查看之后发生了什么错误。

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

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