使用paperclip和Amazon s3的开发错误

Ric*_*wis 4 heroku amazon-s3 paperclip ruby-on-rails-3

我的应用程序在heroku上运行,并已配置为使用亚马逊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.
Run Code Online (Sandbox Code Playgroud)

我的更新动作

 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
Run Code Online (Sandbox Code Playgroud)

虽然经过一些阅读后看来是因为我在欧盟使用了一个水桶(不是默认的美国水桶)

我有两个桶,一个用于开发,一个用于生产.并创建了一个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
Run Code Online (Sandbox Code Playgroud)

和我的食谱模型配置

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"
Run Code Online (Sandbox Code Playgroud)

有没有人得到一个解决方案,我已经尝试过这个例如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{^/}, "")}"
   }
Run Code Online (Sandbox Code Playgroud)

Chr*_*ers 13

尝试将url选项设置has_attached_file":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"
Run Code Online (Sandbox Code Playgroud)

请参阅RDoc Paperclip::Storage::S3.

  • 如果其他人使用此答案,您必须定义路径,否则您将收到"无限插值"错误.谢谢Chris的回答. (2认同)

fgu*_*len 6

对于那些像我一样,url解决方案无效的尝试设置s3_host_name选项:

:s3_host_name => "s3-eu-west-1.amazonaws.com"
Run Code Online (Sandbox Code Playgroud)

看起来欧洲节点有这个问题.

取自这里