2012-05-17 28 views
7

我一直試圖讓carrierwave與amazon s3一起工作。而不是carrierwave,Excon :: Errors :: MovedPemanently在RegistrationsController#更新錯誤

storage :s3 

我有

storage :fog 

將其更改爲存儲:S3給出了一個直接的錯誤

https://stackoverflow.com/questions/10629827/carrierwave-cant-convert-nil-into-string-typeerror-when-using-s3

所以我改成了存儲:霧像下面的RDoc的說。

http://rubydoc.info/gems/carrierwave/frames

然而,當我嘗試上傳一張圖片,我得到這個瘋狂的錯誤。即時通訊使用設計寶石。

我的全堆棧跟蹤

Excon::Errors::MovedPermanently in RegistrationsController#update 

Excon::Errors::MovedPermanently (Expected(200) <=> Actual(301 Moved Permanently) 
    request => {:connect_timeout=>60, :headers=>{"Content-Length"=>95472, "Content-Type"=>"image/jpeg", "x-amz-acl"=>"private", "Cache-Control"=>"max-age=315576000", "Date"=>"Thu, 17 May 2012 05:28:55 +0000", "Authorization"=>"AWS AKIAIN6SC3YSGBSUKV4Q:kZOG9mG01jYn48ImFMYbgxAAQRk=", "Host"=>"user.a.777.s3-eu-west-1.amazonaws.com:443"}, :instrumentor_name=>"excon", :mock=>false, :read_timeout=>60, :retry_limit=>4, :ssl_ca_file=>"/Users/sasha/.rvm/gems/ruby-1.9.3-p125/gems/excon-0.13.4/data/cacert.pem", :ssl_verify_peer=>true, :write_timeout=>60, :host=>"user.a.777.s3-eu-west-1.amazonaws.com", :path=>"/uploads%2Fuser%2Fimage%2F59%2Fidea.jpg", :port=>"443", :query=>nil, :scheme=>"https", :body=>#<File:/Users/sasha/Desktop/rails_projects/blue_eyes/public/uploads/tmp/20120516-2228-19160-9893/idea.jpg>, :expects=>200, :idempotent=>true, :method=>"PUT"} 
    response => #<Excon::Response:0x007fd72a146820 @body="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>PermanentRedirect</Code><Message>The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.</Message><RequestId>F5F5AF888E837622</RequestId><Bucket>user.a.777</Bucket><HostId>IShK3GIthzCQysLOKXnR+ijJiHmMuUtXBOpFxQM4uCvJgkEHfmFn43LL4oWmpT82</HostId><Endpoint>s3.amazonaws.com</Endpoint></Error>", @headers={"x-amz-request-id"=>"F5F5AF888E837622", "x-amz-id-2"=>"IShK3GIthzCQysLOKXnR+ijJiHmMuUtXBOpFxQM4uCvJgkEHfmFn43LL4oWmpT82", "Content-Type"=>"application/xml", "Transfer-Encoding"=>"chunked", "Date"=>"Thu, 17 May 2012 05:29:00 GMT", "Connection"=>"close", "Server"=>"AmazonS3"}, @status=301>): 
    app/controllers/registrations_controller.rb:30:in `update' 

我不知道這是什麼意思,甚至。

在我的初始化/ carrierwave.rb我有..

CarrierWave.configure do |config| 
    config.fog_credentials = { 
    :provider    => 'AWS',  # required 
    :aws_access_key_id  => 'somekey',  # required 
    :aws_secret_access_key => 'secretkey',  # required 
    :region     => 'eu-west-1' # optional, defaults to 'us-east-1' 
    } 
    config.fog_directory = 'bucket.name'      # required 
    #config.fog_host  = 'https://s3.amazonaws.com'   # optional, defaults to nil 
    config.fog_public  = false         # optional, defaults to true 
    config.fog_attributes = {'Cache-Control'=>'max-age=315576000'} # optional, defaults to {} 
end 

和我的上傳文件有

#storage :s3 
    storage :fog 
    def store_dir 
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" 
    end 

我的寶石文件有

gem 'carrierwave' 
gem 'thin' 
gem 'fog' 

,當我啓動我的服務器,而不是webrick,它在開發中也很薄弱。

是我的配置錯了嗎? 幫助將不勝感激! 我曾經超級卡在這個carrierwave/s3的問題

回答

17

我在今天早些時候遇到了這個問題,這是該地區的問題。只要把它拿出來,讓它由默認設置。

CarrierWave.configure do |config| 
    config.fog_credentials = { 
    :provider    => 'AWS',  # required 
    :aws_access_key_id  => 'somekey',  # required 
    :aws_secret_access_key => 'secretkey'  # required 
    } 
    config.fog_directory = 'bucket.name'      # required 
    #config.fog_host  = 'https://s3.amazonaws.com'  # optional, defaults to nil 
    config.fog_public  = false        # optional, defaults to true 
    config.fog_attributes = {'Cache-Control'=>'max-age=315576000'} # optional, defaults to {} 
end 
+1

謝謝!多數民衆贊成在我做了太多=) – Sasha

2

工作對我來說這個配置

config.fog_directory = 'bucket_name'     
config.fog_host  = 'https://s3-eu-west-1.amazonaws.com/bucket_name'  
+0

謝謝!完全工作。 – svs

2

我有同樣的問題。

按照以下3個步驟爲我工作。

1.更改創建當剷鬥

2.Edit我carrierwave.rb文件(如下所示)的默認區域

initializers/carrierwave.rb:在命令行

if Rails.env.production? 
    CarrierWave.configure do |config| 
    config.fog_credentials = { 
     :provider    => 'AWS', 
     :aws_access_key_id  => ENV['S3_ACCESS_KEY'], 
     :aws_secret_access_key => ENV['S3_SECRET_KEY'], 
     :region => ENV['S3_REGION'] 
    } 
    config.fog_directory  = ENV['S3_BUCKET'] 
    end 
end 

3.Configure的Heroku如:heroku config:set S3_REGION='your region'

0

就像@Jason Bynum所說的,不要指定區域並讓它默認。

如果仍然失敗,不要擔心,這時候,你喜歡your region specified is wrong and should be xxx

的Heroku會給暗示你知道如何填寫該地區現在:)

的以下的工作我:

CarrierWave.configure do |config| 
    config.fog_credentials = { 
     provider:    'AWS',      # required 
     aws_access_key_id:  ENV['S3_KEY'],      # required 
     aws_secret_access_key: ENV['S3_SECRET'],      # required 
     region:    'ap-southeast-1',     # optional, defaults to 'us-east-1' 

    } 
    config.fog_directory = 'your_bucket_name'       # required 
    config.fog_public  = false          # optional, defaults to true 
    config.fog_attributes = { 'Cache-Control' => "max-age=#{365.day.to_i}" } # optional, defaults to {} 
end 

的Gemfile:

gem 'carrierwave', '0.10.0' 
gem 'fog', '1.36.0' 
相關問題