I am checking the file size of an uploaded file and storing it in a
column. It will work just fine when the user uploads any files other
Word, Excel, Powerpoint, .zip and more all work fine.
This is my model asset.rb that handles the file upload.
self.filename = base_part_of(newfile_field.original_filename)
self.filetype = newfile_field.content_type.chomp
self.filesize = File.size(newfile_field) ### It fails on this line
The error I get is: “can’t convert StringIO into String”
I’m sure there’s an easier method/property to get the file size of the
uploaded file. Like, reading the HTTP headers?
How do they get the file size in the validator?
validates_filesize_of :field, :in => 15.kilobytes…1.megabyte
Thanks for any leads,