I am not using carrierwave or paperclip for my file upload. I want to find out the file extension and the size in bytes of a file that the user has uploaded? Any ideas on how I can achieve this?
File.size(doc.filename)
Just throw the name of the file into the curly brackets and you should be set.
If you want KB/MB use:
number_to_human_size(File.size(doc.filename))
EDIT:
You can use the exact path or Pathname
1.9.3p125 :005 > x=Pathname.new("/usr/bin/ruby")
=> #<Pathname:/usr/bin/ruby>
1.9.3p125 :006 > File.size(x)
=> 5488
For extension:
File.extname("test.rb") #=> ".rb"
params[:file].size
File.extname(params[:file].original_name)
or params[:file].original_name.match(/\.(\S*)$/).try(:"[]",1)
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