From: Tanaka Akira Date: 2003-11-05T02:20:47+09:00 Subject: Re: CGI uses file size to distinguish between regular values and files In article <1067952745.419615.23337.nullmailer@picachu.netlab.jp>, matz@ruby-lang.org (Yukihiro Matsumoto) writes: > How about > > require 'fileutils' > File.open(upload, 'w') {|f| FileUtils.copy_stream(file,f)} > > ? It's bit longer, but works now without any modifies. I see. It is a solution but I found that I misunderstand the problem. I thought that we cannot assume cgi['file'] has an actual file. But the assumption was correct in ruby-1.6 because always cgi.rb use Tempfile since StringIO was not bundled. It is documented in cgi.rb: # === Get multipart form values # # require "cgi" # cgi = CGI.new # value = cgi['field_name'] # <== value string for 'field_name' # value.read # <== body of value # value.local_path # <== path to local file of value # value.original_filename # <== original filename of value # value.content_type # <== content_type of value The existence of the method `local_path' means that there is an actual file in somewere. But now local_path returns invalid pathname such as "" for smaller file. So the problem is an incompatibility between ruby-1.6 and ruby-1.8. It can be solved by: * obsolete `local_path' and update documentation, * don't use StringIO or * switch StringIO to Tempfile when local_path is called. -- Tanaka Akira