Troubles setting up Paperclip + AWS S3 for image storing in our Rails3/Heroku App

拜拜、爱过 提交于 2019-12-04 09:57:46
user670562

excellent question. I spent quite some time with a similar issue a while ago

The primary issue is that you need to move the following code into it's own initializer file:

if Rails.env == "production" 
   S3_CREDENTIALS = { :access_key_id => ENV['S3_KEY'], :secret_access_key => ENV['S3_SECRET'], :bucket => "ourbucket"} 
 else 
   S3_CREDENTIALS = Rails.root.join("config/s3.yml")
end

Then, you should add the following line to your model where you have *has_attached_file :photo* The line to add is.

:s3_credentials => S3_CREDENTIALS,

This is what you were missing before.

Also, for when you declare your bucket name, make sure that is for standard us. If you use one of the other locations, you'll have to update the path appropriately.

Hope this helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!