Paperclip and Amazon S3 how to do paths?

Rails beginner picture Rails beginner · Sep 19, 2011 · Viewed 9.3k times · Source

How do I create paths with paperclip when using Amazon S3?

My directory on my bucket is:

/image/:id/:filename

My model:

  has_attached_file :image,
    :storage => :s3,
    :bucket => 'mybucket',
    :s3_credentials => {
      :access_key_id => ENV['S3_KEY'],
      :secret_access_key => ENV['S3_SECRET']
    }

Answer

Tim Scollick picture Tim Scollick · Sep 19, 2011

Try this:

  has_attached_file :image,
    :storage => :s3,
    :bucket => 'mybucket',
    :path => "/image/:id/:filename",
    :s3_credentials => {
      :access_key_id => ENV['S3_KEY'],
      :secret_access_key => ENV['S3_SECRET']
    }