AWS / s3&回形针图像无法保存

时间:2015-08-12 16:36:18

标签: ruby-on-rails amazon-web-services heroku amazon-s3 paperclip

我正在尝试使用AWS&在Heroku上部署的应用程序上用户上传的Paperclip,但是当我尝试上传附有图像的帖子时,我一直收到此错误:

**

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:

**

这是我的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'

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

老实说,我不知道我在做什么,所以任何帮助都会受到赞赏。

1 个答案:

答案 0 :(得分:0)

听起来好像是错误,您没有在您的heroku应用上使用AWS进行身份验证。这很可能是因为您没有设置ENV个变量。您需要运行以下终端命令。

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"

因此,您将从AWS获得所有这些值。然后在终端中运行这些命令,并设置ENV变量。那是第二步。然后你需要看看之后出现了什么错误。