Rails - 回形针不适用于 AWS

Rails - Paperclip not working with AWS

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.

在添加最后一行之前,我遇到了 S3 错误 (The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.)。添加后,文件将上传到本地存储而不是 S3。

我也试过将这些添加到 paperclip.rb,但出现了不同的错误。当我添加所有 3 行时,出现错误 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'

宝石文件:

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

我也试过 rake assets:precompile RAILS_ENV=production 但似乎没有帮助

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

AWS_REGION: us-west-1

S3_BUCKET_NAME: groundwork-images-2

AWS_ACCESS_KEY_ID: ...

AWS_SECRET_ACCESS_KEY: ...

我已经设置了 IAM 帐户并在 us-west-1 区域创建了存储桶。我需要在 S3 上做些什么来添加权限吗?

我不明白为什么 Paperclip 将它存储在本地,如果配置是针对 S3 的,没有任何错误或任何东西..

现在可以使用了

这是我使用的代码:

#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 指出我需要合并 2 个配置语句。我还将图像上传到 S3 存储桶以仔细检查存储桶 name/region。我重新创建了 IAM 凭据。