2012-12-15 62 views
4

我有我的應用程序在heroku上運行,並配置爲使用亞馬遜s3保存上傳到存儲桶的所有資產。所有工作正常。所以,當我試圖在本地上傳圖片(開發)我得到以下錯誤使用回形針和亞馬遜s3開發錯誤

AWS::S3::Errors::PermanentRedirect in RecipesController#update 
The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint. 

我的更新動作

def update 
@recipe = Recipe.find(params[:id]) 

if @recipe.update_attributes(params[:recipe]) 
    redirect_to my_recipes_path, :notice => "Successfully updated recipe" 
else 
render :action => 'edit' 

end 
end 

雖然有些人讀它似乎那是因爲我使用的水桶後,歐盟(不是默認的美國)

我有兩個桶,一個用於開發,一個用於生產。並創建了一個s3.yml文件來保存憑證,但我認爲使用ENV變量會更好,我使用Ubuntu並且可以更新我的.bashrc文件?不肯定在那一個。不管怎麼樣我s3.yml文件(實際密鑰的安全刪除obviosuly)

development: 
access_key_id: KEY 
secret_access_key: KEY 
bucket: assets.recipesappdev 

production: 
access_key_id: KEY 
secret_access_key: KEY 
bucket: assets.recipesapp 

和我的食譜模型配置

has_attached_file :avatar, 
:styles => { :myrecipes => "260x180#", :showrecipe => "600x300#", :medium => "300x300>", :thumb => "100x100>" }, 
:storage => :s3, 
:s3_credentials => "#{Rails.root}/config/s3.yml", 
    :path => "/images/:id/:style.:extension" 

有沒有人有一個修復此,我曾經嘗試這樣做,例如http://www.conandalton.net/2011/02/paperclip-s3-and-european-buckets.html但是,這並不工作,但我的初始化可能是錯的,我試過配置,以滿足我的應用程序

Paperclip.interpolates(:s3_eu_url) { |assets, style| 
"#{assets.s3_protocol}://s3-eu-west-1.amazonaws.com/#{assets.recipesappdev} /#{assets.path(style).gsub(%r{^/}, "")}" 
    } 
+0

兩者這裏有問題的解釋:https://devcenter.heroku.com/articles/paperclip-s3#international-users-additional-configuration – TTT

回答

13

嘗試在設置url選項至":s3_domain_url"。 (不要忘了用引號括起來。)

has_attached_file :avatar, 
        :styles => { :myrecipes => "260x180#", :showrecipe => "600x300#", :medium => "300x300>", :thumb => "100x100>" }, 
        :storage => :s3, 
        :s3_credentials => "#{Rails.root}/config/s3.yml", 
        :path => "/images/:id/:style.:extension", 
        :url => ":s3_domain_url" 

查看RDoc的Paperclip::Storage::S3

+1

你剛剛結束了一天的酷刑,非常感謝你 – Richlewis

+0

希望我知道更多具體細節,但是我記得如果你在歐洲使用S3服務器,閱讀關於需要使用's3_domain_url'的東西。很高興我的猜測是正確的,你可以繼續你的生活! –

+2

如果其他人使用此答案,您必須定義路徑,否則您將收到「無限插值」錯誤。感謝Chris的回答。 – christoshrousis

6

對於那些像我一樣,在url解決方案是行不通的嘗試設置s3_host_name選項:

:s3_host_name => "s3-eu-west-1.amazonaws.com" 

看起來像歐洲的節點有這個問題。

here

+1

我在美國,這對我仍然有幫助。謝謝! – vise

+0

謝謝!這工作! :-D –