From: Dmitry Borodaenko Date: 2003-11-04T04:37:19+09:00 Subject: Re: CGI uses file size to distinguish between regular values and files On Mon, Nov 03, 2003 at 11:40:48PM +0900, Austin Ziegler wrote: > Why should I have to make that distinction in *my* code? I've got a > Perl app that I plan to port over to Ruby at some point, and it allows > file uploads (up to a couple megabytes in size). Indeed, the way that > I deal with the file uploads never touches the filesystem from the > perspective of my application (the file "string" goes directly into a > MySQL database). If I have to step into my own filehandling, then I > may not port this app to Ruby even though it's a fine candidate for it > otherwise. 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. 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. > The library should provide me the raw data. If I decide something is a file > and want to take some shortcuts with it, then the library can provide me > additional information (e.g., CGI.tempfile?(parameter_index)) and > functionality to access that implementation detail, but I should never > *have* to make the distinction in my application code. Ever. YMMV. I'd rather learn the difference between StringIO and Tempfile _once_, than learn special API for handling this difference in each new library I use. And introspection API is in Ruby for a reason, too ;) Not that I object to this behaviour of CGI module being more explicitly documented at least in comments in cgi.rb. -- Dmitry Borodaenko