[Rails] File.size() on Uploaded Images Fail

Phillip Hutchings
Mon, 29 May 2006 21:46:57 -0000

>    def newfile=(newfile_field)
>     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 for
> images...
>   end
>
> The error I get is: "can''t convert StringIO into String"


File.size tells you the size of the file you give it by name, eg
File.size(''/etc/passwd/''). You have a StringIO object, which
is just
another type of IO object. You want to use newfile_field.size.

--
Phillip Hutchings