【问题标题】:Development error using paperclip and Amazon s3使用回形针和 Amazon s3 的开发错误
【发布时间】:2012-12-03 08:37:59
【问题描述】:

我的应用程序在 heroku 上运行,并已配置为使用 Amazon 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 文件(为安全起见删除了实际密钥)

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{^/}, "")}"
   }

【问题讨论】:

标签: ruby-on-rails-3 heroku amazon-s3 paperclip


【解决方案1】:

尝试将has_attached_file 上的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"

请参阅Paperclip::Storage::S3 的 RDoc。

【讨论】:

  • 希望我知道更多细节,但我记得读过一些关于如果您在欧洲使用 S3 服务器需要使用 s3_domain_url 的内容。很高兴我的猜测是正确的,你可以继续你的生活!
  • 如果其他人使用此答案,您必须定义路径,否则您将收到“无限插值”错误。感谢克里斯的回答。
【解决方案2】:

对于像我这样,url 解决方案不起作用的人,请尝试设置 s3_host_name 选项:

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

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

取自here

【讨论】:

  • 我在美国,这仍然对我有帮助。谢谢!
猜你喜欢
  • 1970-01-01
  • 2011-12-27
  • 1970-01-01
  • 1970-01-01
  • 2013-07-27
  • 2012-07-10
  • 1970-01-01
  • 2011-03-27
  • 2018-04-09
相关资源
最近更新 更多