From: Austin Ziegler Date: 2003-11-04T06:29:54+09:00 Subject: Re: CGI uses file size to distinguish between regular values and files On Tue, 4 Nov 2003 04:37:19 +0900, Dmitry Borodaenko wrote: > On Mon, Nov 03, 2003 at 11:40:48PM +0900, Austin Ziegler wrote: [snip] > You've missed the question in the beginning of this thread: > > For starters, how would one move a small file, treated as > StringIO, to another location? With Tempfile, you just do > Tempfile#local_path, and move away. But it's not so straight > forward with StringIO. > > Obviously, asker _wants_ his own file handling. I didn't miss that. What's wrong, though, is that the CGI library is returning different values for parameters based on the total size of the data. I'm sorry, but that's broken. Remember -- one of the complaints was based on the size of the upload: If I upload just one file that brings the content_length above 10240, ALL fields in the request is treated as Tempfiles. If I'm uploading a small file that keeps the content_length below 10240, all the fields -- including the file -- is treated as StringIOs. The problem is that this means that access to the data is much harder to deal with if you're dealing with a file upload. Like I said; I don't like the Perl implementation, but it's *consistent*. This appears to be highly inconsistent. > Since I do that in Samizdat, I know at least one reason for that: > I don't want to add two extra layers of indirection (Ruby and SQL) > between Apache (or rsync or Gnutella) and a hundred-megabyte video > file on disk. I think you're misunderstanding. I *want* to be able to deal with the data in either way. I'm looking at this from the perspective of two different applications: Ruwiki and Bug Traction. Ruwiki may support file uploads at some point. If this happens, there will be multiple fields *plus* the file itself. The fields, I want to accesss as pure data. The file, on the other hand, will be handled either as a file (by the flatfiles backend) or as raw data (by a putative database backend). Bug Traction, when I port it to Ruby, by default has a database backend, so I *only* want to deal with the data in a raw data mode. Ideally, I should be able to do something like: cgi['file'] # => returns the data of the file cgi['file'].IO? # => +true+ I realize that this isn't really the best way, but maybe an alternative means might be: cgi['file'] # => returns the data of the file cgi['file'].tempfile # => returns -- or creates to return -- an # associated tempfile for the data IMO, this would be much better than the current situation. I should *not* have to make my program work differently based on whether I've uploaded a large enough file or not -- or even if I'm uploading a file or not. -austin -- austin ziegler * austin@halostatue.ca * Toronto, ON, Canada software designer * pragmatic programmer * 2003.11.03 * 15.59.28