2012-12-15 65 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 –