用曲别针开发错误和亚马逊S3 [英] Development error using paperclip and Amazon s3

查看:141
本文介绍了用曲别针开发错误和亚马逊S3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Heroku上运行我的应用程序和配置,以节省上传到使用亚马逊的水桶全部资产s3.That一切工作正常。所以,当我试图在本地上传图片(开发中)我得到以下错误

  AWS :: S3 ::错误:: PermanentRedirect中的RecipesController#更新
您尝试访问的桶必须使用指定的端点解决。请发送到这个端点今后所有申请。
 

我的更新动作

 高清更新
 @recipe = Recipe.find(PARAMS [:ID])

 如果@ recipe.update_attributes(PARAMS [:配方])
  redirect_to时my_recipes_path,:通知=> 成功更新配方
 其他
 渲染:行动=> '编辑'

结束
结束
 

虽然之后出现它的一些阅读是因为我用水桶在欧盟(不是默认美国的)

我有两个桶,一个用于开发,一个用于生产。并创建了一个s3.yml文件来保存凭据,但我认为这将是更好地使用ENV变量,我使用Ubuntu,我可以更新我的.bashrc文件?不肯定在那一个......反正我s3.yml文件(删除了安全实际密钥obviosuly)

 的发展:
access_key_id:KEY
secret_access_key:KEY
斗:assets.recipesappdev

生产:
access_key_id:KEY
secret_access_key:KEY
斗:assets.recipesapp
 

和我的食谱型号配置

  has_​​attached_file:头像,
:风格=> {:myrecipes => 260x180#,:showrecipe => 600×300#,:中=> 300×300>中,:拇指=&​​GT; 100×100>中},
 :存储=> :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.s3_protocol}://s3-eu-west-1.amazonaws.com/# {assets.recipesappdev} /#{assets.path(style).gsub(%r{^/},) }
   }
 

解决方案

尝试设置网​​址的选项 has_​​attached_file :s3_domain_url。 (不要忘了用引号括住。)

  has_​​attached_file:头像,
                  :风格=> {:myrecipes => 260x180#,:showrecipe => 600×300#,:中=> 300×300>中,:拇指=&​​GT; 100×100>中},
                  :存储=> :S3,
                  :s3_credentials => #{Rails.root} /config/s3.yml
                  :PATH => /images/:id/:style.:extension
                  :URL => :s3_domain_url
 

见的RDoc <一个href="http://rdoc.info/github/thoughtbot/paperclip/Paperclip/Storage/S3"><$c$c>Paperclip::Storage::S3.

I have my app running on heroku and have configured to save all assets uploaded to a bucket using Amazon s3.That all works fine. So when i tried to upload an image locally (development) i get the following error

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.

My update action

 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

Though after some reading it appears it is because I am using a bucket in the EU (not the default US one)

I have two buckets, one for development and one for production. and have created a s3.yml file to hold the credentials, though I think it would be better to use ENV variables, I use Ubuntu and I could update my .bashrc file? not to sure on that one.. Anyway my s3.yml file (actual keys removed for security 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

and my recipe model config

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"

Has anyone got a fix for this, I have tried this for example http://www.conandalton.net/2011/02/paperclip-s3-and-european-buckets.html but that doesnt work, though my initializer may be wrong, i tried configuring to suit my app

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

解决方案

Try to set the url option on has_attached_file to ":s3_domain_url". (Don't forgot to surround with quotes.)

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"

See the RDoc for Paperclip::Storage::S3.

这篇关于用曲别针开发错误和亚马逊S3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆