Reputation: 2672
I am using paperclip to save images in s3. The following is the code in my model
has_attached_file :pic, :storage => :s3, :s3_credentials => "#{Rails.root}/config/s3.yml",
:url => '/image/file/:basename.:extension',
:path => '/image/file/:basename.:extension',
:bucket => 'Test'
And the problem is whenever i save the image with same name, the image gets replaced if there is already an image with that name. I wanted to change the name of the file. I am saving the image during the creation of new item. So can i able to use the id of the item as name of the file so that the image will be unique? If yes then how can i do it? please help me.
Upvotes: 2
Views: 2038
Reputation: 2121
This might help you:
Generating a unique file path with Polymorphic Paperclip
http://trevorturk.com/2009/03/22/randomize-filename-in-paperclip/
Upvotes: 3