Paperclip Amazon S3 setup with Heroku

我的梦境 提交于 2019-11-29 01:57:37

问题


has_attached_file :image, :storage => :s3, :s3_credentials => "#{RAILS_ROOT}/config/s3.yml", :path => "/:style/:filename"

I'm not sure what :path => "/:style/:filename" is.

I also want to to include the style for this attached image, is that what the :path is? the style I want is this: :styles => { :medium => "275x275>", :thumb => "175x155>" }

Basically what's going on here is that I'm setting up on heroku and I'm having to use S3 which seems straightforward just not used to this attachment convention stuff.

Also, I just signed up for an S3 account... but heroku was spouting that its free or something. What's the deal with that?


回答1:


The 'path' specifies the location on S3 where the files will be stored. Thus, if you specify an attachment as:

 has_attached_file :image, 
    :styles => { :medium => "275x275>", :thumb => "175x155>" },
    :storage => :s3, :s3_credentials => "#{RAILS_ROOT}/config/amazon_s3.yml",
    :path => "user/:attachment/:style/:id.:extension"

A sample URL will be:

http://s3.amazonaws.com/bucket/user/image/thumb/347853856.jpg

Finally, S3 is NOT free (Heroku simply states transfer / uploads are not counted in the usage based calculations). Heroku's documentation is excellent if you need further information.




回答2:


Note that in Rails 3.1 and above, it should be Rails.root and not RAILS_ROOT



来源:https://stackoverflow.com/questions/3435246/paperclip-amazon-s3-setup-with-heroku

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