Hi… I was reading this old thread ("Random File Name (part 2)" -
http://groups.google.com/group/paperclip-plugin/browse_thread/thread/c45922d0dc2fee83)
last week after I got a requirement to encrypt/obfuscate Paperclip
attachment filenames... not in S3, but right on my own server using
file system storage.
I got it to work easily using a new interpolation like this:
has_attached_file :pdf,
:url => "#{ActionController::Base.relative_url_root}/:class/:id/
download",
:path => ':rails_root/some/path/
to/:attachment/:id/:style/:randomized_name.:extension'
I used an initializer (config/initializers/paperclip.rb) to create
the :randomized_name interpolation like this:
Paperclip.interpolates :randomized_name do |attachment, style|
Digest::MD5.hexdigest attachment.original_filename
end
The cool thing was that authorized end users never see the random name
since my controller uses send_file (with XSendFile) to set the
original name back:
send_file doc.pdf.path,
:type => doc.pdf_content_type,
:filename => doc.pdf_file_name,
:x_sendfile => true
Hope this helps someone else with a similar requirement... - pat
http://patshaughnessy.net