From: Dmitry Borodaenko Date: 2003-11-06T01:45:14+09:00 Subject: Re: CGI uses file size to distinguish between regular values and files On Wed, Nov 05, 2003 at 12:53:01AM +0900, Yukihiro Matsumoto wrote: > How about > > require 'fileutils' > File.open(upload, 'w') {|f| FileUtils.copy_stream(file,f)} > > ? It's bit longer, but works now without any modifies. That is better than my ftools-based solution, since it solves the problem of differentiating between StringIO and Tempfile (although it won't work with Ruby 1.6, if anyone still cares about that). But I think the harder problem lies earlier in the execution path, when application decides whether to handle the parameter value as a String or as IO. I don't see any simple way of moving responsibility for this decision from application to cgi.rb library without getting bitten by the corner case of a large upload that wouldn't fit into memory. That is, unless Ruby learns to automatically convert strings to tempfiles as soon as they become too large, which would be quite a feat... :) In the absence of such feat, I think it would be nice to have def multipart? @multipart end in class CGI in order to make detection of multipart data more obvious. -- Dmitry Borodaenko