Rails - Paperclip不与AWS合作

时间:2017-03-01 14:49:59

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

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'

的Gemfile:

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的话,没有任何错误或任何错误。

1 个答案:

答案 0 :(得分:0)

它现在正在工作

以下是我使用的代码:

#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存储桶以仔细检查存储桶名称/区域。我重新创建了IAM凭据。