首页 文章

Rails - Paperclip不与AWS合作

提问于
浏览
1

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 ..

2 回答

  • 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凭据 .

  • -1

    既然我不能发表评论:

    你告诉那个 class 你将它存储在AWS上吗?

    你需要在课堂下放置: has_attached_file : storage => :s3

    更多信息:http://www.rubydoc.info/gems/paperclip/Paperclip/Storage/S3

相关问题