简体   繁体   English

Rails - Paperclip不与AWS合作

[英]Rails - Paperclip not working with AWS

Paperclip is working without AWS, but when I try to use S3 storage it breaks. Paperclip在没有AWS的情况下工作,但是当我尝试使用S3存储时,它会中断。

#production.rb
    config.paperclip_defaults = {
        storage: :s3,
        s3_region: ENV["AWS_REGION"],
        s3_credentials: {
          # s3_host_name: ENV["AWS_HOST_NAME"],
          bucket: ENV["S3_BUCKET_NAME"],
          access_key_id: ENV["AWS_ACCESS_KEY_ID"],
          secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"]
          }
  }

    config.paperclip_defaults = { s3_host_name: "s3-us-west-1.amazonaws.com", }
    # Added this line to fix: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.

Before adding the last line I got an S3 error ( The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint. ). 在添加最后一行之前,我收到了S3错误( The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint. )。 After adding it the files get uploaded to local storage instead of S3. 添加后,文件将上传到本地存储而不是S3。

I've also tried adding these to paperclip.rb, with different errors. 我也尝试将这些添加到paperclip.rb,但有不同的错误。 When I add all 3 lines I get the error Read-only file system @ dir_s_mkdir - /projects 当我添加所有3 Read-only file system @ dir_s_mkdir - /projects我得到错误Read-only file system @ dir_s_mkdir - /projects

#paperclip.rb
# 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-1.amazonaws.com'

Gemfile: 的Gemfile:

gem "paperclip", "~> 5.0.0"
gem 'aws-sdk', '~> 2.3'

I've also tried rake assets:precompile RAILS_ENV=production which didn't seem to help 我也尝试过rake assets:precompile RAILS_ENV=production似乎没有帮助

edit: AWS_HOST_NAME: s3-us-west-1.amazonaws.com 编辑:AWS_HOST_NAME:s3-us-west-1.amazonaws.com

AWS_REGION: us-west-1 AWS_REGION:us-west-1

S3_BUCKET_NAME: groundwork-images-2 S3_BUCKET_NAME:groundwork-images-2

AWS_ACCESS_KEY_ID: ... AWS_ACCESS_KEY_ID:...

AWS_SECRET_ACCESS_KEY: ... AWS_SECRET_ACCESS_KEY:...

I've setup IAM account and created the bucket in the us-west-1 region. 我已经设置了IAM帐户并在us-west-1区域创建了存储桶。 Is there anything on S3 that I need to do to add permissions? S3上有什么需要做的才能添加权限吗?

I can't understand why Paperclip is storing it locally, with out any errors or anything if the config is for S3.. 我无法理解为什么Paperclip在本地存储它,没有任何错误或任何东西,如果配置是为S3 ..

It's working now 它现在正在运作

Here is the code I used: 这是我使用的代码:

#production.rb
    config.paperclip_defaults = {
        storage: :s3,
        s3_region: ENV["AWS_REGION"],
            s3_host_name: "s3-us-west-2.amazonaws.com",
        s3_credentials: {
          # s3_host_name: ENV["AWS_HOST_NAME"],
          bucket: ENV["S3_BUCKET_NAME"],
          access_key_id: ENV["AWS_ACCESS_KEY_ID"],
          secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"]
          }
  }

@meagar pointed out that I needed to combine the 2 config statements. @meagar指出我需要结合2个配置语句。 I also uploaded an image to the S3 bucket to double check bucket name/region. 我还将图像上传到S3存储桶以仔细检查存储桶名称/区域。 And I recreated IAM credentials. 我重新创建了IAM凭据。

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

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