Tony Beninate
Tony Beninate

Reputation: 1985

Paperclip S3 image path issue

I've just upgraded from Rails 3.1 to Rails 3.2.6 and my paperclip photo paths are now broken on production.

photo.rb

if Rails.env == "production"
  has_attached_file :image,
    :storage => :s3,
    :s3_credentials => S3_CREDENTIALS,
    :url => "/app/public/system/images/:id/:style/:basename.:extension",

I need the resulting path to be like so: http://s3.amazonaws.com/photoramblr/app/public/system/images/5/thumb_large/image.jpg

but instead the above url settings result in: http://s3.amazonaws.com/photoramblr/app/public/app/public/system/images/5/thumb_large/image.jpg

I've also tried setting the paperclip url to :url => "/system/images/:id/:style/:basename.:extension" but that resulted in this url: http://s3.amazonaws.com/photoramblr/images/5/thumb_large/image.jpg

Any thoughts on how I can set this properly?

UPDATE: Well, I still don't understand how it's working, but I 'fixed' this by just moving the files to the location it was looking in.

Upvotes: 1

Views: 1530

Answers (1)

dantheta
dantheta

Reputation: 1107

Try adding a path parameter replacing the url parameter and specifying the path under the bucket name where your file will be stored and the URL will be constructed from the bucket and the path supplied. Here is a link to paperclip s3 docs for further details. If you supply a url parameter, it is treated relative to your "app/public". That explains why you're resulting image path doubles "app/public". Ryan Bate's paperclip tutorial also explains this behaviour. In your case your code will be as shown below;

if Rails.env.production?
  has_attached_file :image,
    :storage => :s3,
    :s3_credentials => S3_CREDENTIALS,
    :path => "app/public/system/images/:id/:style/:basename.:extension",

Your resulting link will be (I'm assuming your bucket name is photorambler from your link); s3.amazonaws.com/photorambler/app/public/system/images/5/thumb_large/image.jpg

Upvotes: 1

Related Questions