Forum: Ruby on Rails Multiple file uploads

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
10c741d575988433e3fcd04133f3c462?d=identicon&s=25 Sebastian Friedrich (Guest)
on 2006-03-23 02:22
(Received via mailing list)
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.

sebastian
Bf66e10c8fc4abefebde0425e7f6f15a?d=identicon&s=25 Norman Timmler (Guest)
on 2006-03-23 13:52
(Received via mailing list)
Am Mittwoch, den 22.03.2006, 19:20 -0600 schrieb Sebastian Friedrich:
>   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
This topic is locked and can not be replied to.