Am Mittwoch, den 22.03.2006, 19:20 -0600 schrieb Sebastian
Friedrich:> I have a form with multiple file upload fields (1-10), of which 2-10
> are optional. So i need to cycle thru all file fields and pick only
> those that have a file attached. Selecting only one file in the form,
> the paramters look simple:
"image"=>{"file_1"=>#<File:/tmp/CGI344.4>,
> "file_2"=>"", "file_3"=>""},
so I tried this:
>
>
> params[:image].each_value do |incomming_file|
> unless incoming_file.empty?
> #do file processing
> end
> end
>
>
> However, this is still causing the empty fields (file_2, file_3 etc)
> to be processed, which raises all sorts of errors as the File.methods
> are not available of course. I tried .nil? and various other tests but
> i simply can''t get it to skip those empty file fields. any ideas?
> Thank you.
Did you examine the class of the empty parameters? Is it File or
StringIO? If yes, you could simply test incoming_file.eof? .
--
Norman Timmler
http://blog.inlet-media.de