using rails with Paperclip, I can use the following to get the filename during a before_create:
extension = File.extname(photo_file_name).downcase
How do I get JUST the file name.. Right now I have photo_file_name which provides the entire file, titlename.pdf
i need just titlename without the .pdf
Thanks
Updating with code:
photo.rb:
before_create :obfuscate_file_name
#Paperclip for photo
has_attached_file :photo,
......
private
def obfuscate_file_name
extension = File.extname(photo_file_name).downcase
fileNameOnly = File.basename(photo_file_name).downcase
self.photo.instance_write(:file_name, "#{fileNameOnly}_#{ActiveSupport::SecureRandom.hex(32)}#{extension}")
end
Use File.basename
with the optional suffix
argument like this:
file_name = File.basename(photo_file_name, File.extname(photo_file_name));
Works on my machine: