ruby-on-rails-3 - 使用回形针和 Amazon s3 的开发错误

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

我的应用程序在 heroku 上运行,并已配置为使用 Amazon s3 保存上传到存储桶的所有 Assets 。一切正常。因此,当我尝试在本地上传图像(开发)时,出现以下错误

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文件(为了安全显然删除了实际 key )
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{^/}, "")}"
   }

最佳答案

尝试设置 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"

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

关于ruby-on-rails-3 - 使用回形针和 Amazon s3 的开发错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13894014/

相关文章:

ruby-on-rails - ruby rails : How do I run an automated rake task on Heroku

web-services - 亚马逊休息服务认证和安全

php - 如何在 Amazon PHP SDK 上设置自定义元数据

amazon-web-services - 使用 AWS S3 同步排除多个文件夹

ruby - Rails 3 NoMethodError(未定义方法 `unserialized_value' 为 "--- []\n":String):

ruby-on-rails - 验证以确保唯一性但忽略空值?

node.js - 错误: failed to connect to [localhost:27017] when running MEAN app on HEROKU

ruby-on-rails - 事件管理员 : How to customize the main menu (at the top of the page)?

ruby-on-rails - Rails 嵌套模型与 formattastic 是否跳过一个字段?

php - 部署到 Heroku 时如何保留 session ?