可以使用 Paperclip 和 AWS S3 在 Heroku 上上传但不能删除图像
Can upload but not delete image on Heroku using Paperclip and AWS S3
已为 Paperclip 正确配置 S3 凭据:
# production.rb (same in development.rb)
config.paperclip_defaults = {
:storage => :s3,
:path => 'photos/:id/:style/:filename',
:s3_credentials => {
:bucket => ENV['aws_bucket'],
:access_key_id => ENV['aws_access_key'],
:secret_access_key => ENV['aws_secret_key']
}
}
我确实看到了 Heroku 中设置的环境变量 UI,我可以上传照片。
然而,当我试图在生产环境中销毁给定模型时,我在日志中收到此错误:
2016-01-14T15:48:48.079923+00:00 app[web.1]: Completed 500 Internal Server Error in 591ms (ActiveRecord: 60.3ms)
2016-01-14T15:48:48.082519+00:00 app[web.1]:
2016-01-14T15:48:48.082522+00:00 app[web.1]: AWS::Errors::MissingCredentialsError (
2016-01-14T15:48:48.082523+00:00 app[web.1]: Missing Credentials.
2016-01-14T15:48:48.082524+00:00 app[web.1]:
2016-01-14T15:48:48.082525+00:00 app[web.1]: Unable to find AWS credentials. You can configure your AWS credentials
2016-01-14T15:48:48.082526+00:00 app[web.1]: a few different ways:
2016-01-14T15:48:48.082526+00:00 app[web.1]:
2016-01-14T15:48:48.082527+00:00 app[web.1]: * Call AWS.config with :access_key_id and :secret_access_key
2016-01-14T15:48:48.082528+00:00 app[web.1]:
2016-01-14T15:48:48.082529+00:00 app[web.1]: * Export AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to ENV
2016-01-14T15:48:48.082529+00:00 app[web.1]:
2016-01-14T15:48:48.082530+00:00 app[web.1]: * On EC2 you can run instances with an IAM instance profile and credentials
2016-01-14T15:48:48.082531+00:00 app[web.1]: will be auto loaded from the instance metadata service on those
2016-01-14T15:48:48.082531+00:00 app[web.1]: instances.
2016-01-14T15:48:48.082532+00:00 app[web.1]:
2016-01-14T15:48:48.082533+00:00 app[web.1]: * Call AWS.config with :credential_provider. A credential provider should
2016-01-14T15:48:48.082533+00:00 app[web.1]: either include AWS::Core::CredentialProviders::Provider or respond to
2016-01-14T15:48:48.082534+00:00 app[web.1]: the same public methods.
这一切在本地也能正常工作(显然使用不同的 S3 存储桶)。有什么问题?为什么即使上传工作正常,我还是 AWS::Errors::MissingCredentialsError
只是在生产环境中?
您可能想确保您使用的是 aws-sdk gem v1 而不是 aws-sdk v2。日志使它看起来像您使用的是 v1 ("AWS::")——如果您使用的是 aws-sdk v2,回形针将无法工作。不要认为 Thoughtbot 会继续支持它,我建议您研究使用 jquery-file-uploader (https://devcenter.heroku.com/articles/direct-to-s3-image-uploads-in-rails#pre-signed-post) 直接上传到 s3——请注意,文章未显示 aws-sdk-v2指示。下面链接的答案确实使用 aws-sdk-v2:
Rails direct to S3 upload using aws-sdk gem and jQuery-File-Upload on heroku
已为 Paperclip 正确配置 S3 凭据:
# production.rb (same in development.rb)
config.paperclip_defaults = {
:storage => :s3,
:path => 'photos/:id/:style/:filename',
:s3_credentials => {
:bucket => ENV['aws_bucket'],
:access_key_id => ENV['aws_access_key'],
:secret_access_key => ENV['aws_secret_key']
}
}
我确实看到了 Heroku 中设置的环境变量 UI,我可以上传照片。
然而,当我试图在生产环境中销毁给定模型时,我在日志中收到此错误:
2016-01-14T15:48:48.079923+00:00 app[web.1]: Completed 500 Internal Server Error in 591ms (ActiveRecord: 60.3ms)
2016-01-14T15:48:48.082519+00:00 app[web.1]:
2016-01-14T15:48:48.082522+00:00 app[web.1]: AWS::Errors::MissingCredentialsError (
2016-01-14T15:48:48.082523+00:00 app[web.1]: Missing Credentials.
2016-01-14T15:48:48.082524+00:00 app[web.1]:
2016-01-14T15:48:48.082525+00:00 app[web.1]: Unable to find AWS credentials. You can configure your AWS credentials
2016-01-14T15:48:48.082526+00:00 app[web.1]: a few different ways:
2016-01-14T15:48:48.082526+00:00 app[web.1]:
2016-01-14T15:48:48.082527+00:00 app[web.1]: * Call AWS.config with :access_key_id and :secret_access_key
2016-01-14T15:48:48.082528+00:00 app[web.1]:
2016-01-14T15:48:48.082529+00:00 app[web.1]: * Export AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to ENV
2016-01-14T15:48:48.082529+00:00 app[web.1]:
2016-01-14T15:48:48.082530+00:00 app[web.1]: * On EC2 you can run instances with an IAM instance profile and credentials
2016-01-14T15:48:48.082531+00:00 app[web.1]: will be auto loaded from the instance metadata service on those
2016-01-14T15:48:48.082531+00:00 app[web.1]: instances.
2016-01-14T15:48:48.082532+00:00 app[web.1]:
2016-01-14T15:48:48.082533+00:00 app[web.1]: * Call AWS.config with :credential_provider. A credential provider should
2016-01-14T15:48:48.082533+00:00 app[web.1]: either include AWS::Core::CredentialProviders::Provider or respond to
2016-01-14T15:48:48.082534+00:00 app[web.1]: the same public methods.
这一切在本地也能正常工作(显然使用不同的 S3 存储桶)。有什么问题?为什么即使上传工作正常,我还是 AWS::Errors::MissingCredentialsError
只是在生产环境中?
您可能想确保您使用的是 aws-sdk gem v1 而不是 aws-sdk v2。日志使它看起来像您使用的是 v1 ("AWS::")——如果您使用的是 aws-sdk v2,回形针将无法工作。不要认为 Thoughtbot 会继续支持它,我建议您研究使用 jquery-file-uploader (https://devcenter.heroku.com/articles/direct-to-s3-image-uploads-in-rails#pre-signed-post) 直接上传到 s3——请注意,文章未显示 aws-sdk-v2指示。下面链接的答案确实使用 aws-sdk-v2:
Rails direct to S3 upload using aws-sdk gem and jQuery-File-Upload on heroku