Rename paperclip AWS files after hashing

So you have been starting in Ruby On Rails – and you have started using paperclip to upload your files to AWS?

But you noticed, that URLS like (non working URL – don’t try it) are not a so good idea.
You don’t want to use customers filenames in production AWS links.

So you can easily use a hash instead of real filenames.
just change your paperclip path – configuration from:
path: ':class/:id/:style/:filename'
path: ':class/:id/:style/:hash.:extension'

See paperclip doc for details.
Now your files have nice, random filenames.

But you will quick notice that you con not access your old files anymore – the paperclip algorithm hashes old files as well.

For this case you can use a rake task that will copy (not rename for safety reasons).

You can find this script on github. Feel free to use it or improve it: