How do you get the file extension in a CarrierWave Uploader? I have quite honestly tried everything I can think of. I introspected the crap out of it.
This doesn't work:
def filename
'filename' + self.extension
end
I'm trying to make custom file names and It's not working.
I had a very similar requirement and I solved it this way:
def filename
if original_filename
@name ||= Digest::MD5.hexdigest(File.dirname(current_path))
"#{@name}.#{file.extension}"
end
end
It works fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With