2017-03-01 66 views
1

回形針在沒有AWS的情況下工作,但是當我嘗試使用S3存儲時,它會中斷。Rails - 回形針不適用於AWS

#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:基礎圖像-2

AWS_ACCESS_KEY_ID:...

AWS_SECRET_ACCESS_KEY:...

我設置IAM帳戶,並創造了美西1區的桶。 S3上有什麼需要添加權限嗎?

我不明白爲什麼回形針在本地存放,使用了任何錯誤,或者如果配置是什麼S3 ..

+0

昨天是否發生過這種情況? –

+0

它仍在發生。我不認爲這與S3中斷有關 – Adam12344

+0

這是值得一試的。您是否好意添加您從S3接收到的錯誤消息?另外,您添加的最後一行,是否在第一個配置設置下添加了,在'production.rb'中? –

回答

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憑證。

相關問題