Paperclip Amazon S3 setup with Heroku

2020-02-23 05:08发布

问题:

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