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 https://s3.eu-central-1.amazonaws.com/eventlocation-photos/Foto_aus_meinem_urlaub.jpg?1524001000 (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:
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: