From: Brent W. <bre...@in...> - 2001-01-19 19:14:37
|
>>>"Sailer Holger (ext.)" said: > Hello, > > I'm trying to post files to the server in two ways: > > 1. via cgi: posting an file fails due to: > in cgi.tcl: proc CgiSpawn: > fcopy $sock $fd -command [list CgiCopyDone $sock $fd] -size > $data(count) > -> dependent on size of posted file, CgiCopyDone never got called. There is a timeout setting in cgi.tcl - I wonder if the server is aborting the connection before it has had a chance to push out the file. Do you find any clues in the error log? > cgifile.tml: > <form ENCtype="multipart/form-data" > action="/cgi-bin/testupload.cgi" method="post"> > > --------------------------------- > File <input type="file" name="the_file" accept="application/*"> > <p> > <input type=submit> > </form> > > cgi-bin/testupload.tcl: > puts "Content-Type: text/html" > puts <pre> > fconfigure stdin -translation binary > puts [read stdin $env(CONTENT_LENGTH)] > puts </pre> By the way, it's probably better to dump the file into a file instead of back into the web page. > 2. post file by not calling cgi-process: > -> works with all ascii-files as well as binary files < ~ 80 KB. > fails with bigger binary files. > e.g. compressed tar - archives can't be extracted any more. > > myfile.tml: > --------------- > <form ENCtype="multipart/form-data" action="mytestupload.tml" > method="post"> > > ------------------------- > File <input type="file" name="the_file" accept="application/*"> > <p> > <input type=submit> > </form> > > mytestupload.tml: > ------------------------- One big drawback of using a .tml file for this purpose is that, by default, TclHttpd will buffer all the POST data into memory before calling your page. It will be a lot more efficient to have a custom domain handler that reads the POST data directly from the socket. Make sure you call Url_PrefixInstall with "-readpost 0" Someone should contribute a simple file upload domain handler so folks don't have to keep solving this problem. > <table border=1 cellpadding=2> > [ > set html "" > set fname "unknown.upload" > foreach {n v} [ncgi::nvlist] { > switch -- $n { > the_file { > foreach { vn vv } [lindex $v 0] { > append html "<pre> NAME=$vn VALUE=$vv \n</pre>" > switch -- $vn { > filename { > regsub -all {\\} $vv {/} new > set fname [ file tail $new ] > } > } > } > set fd [ open [ file join / tmp $fname] w] > fconfigure $fd -translation binary > puts -nonewline $fd [ncgi::value the_file] > close $fd > append html [html::h1 "File saved on [ file join / tmp > $fname]"] > } > } > append html [html::row $n [html::tableFromList [lindex $v 0]]] > } > set html > ] > </table> > > > I'm using tclhttpd3.2.1 and tcl8.3 / tcl8.3.2 and tcllib0.8 (no threads). > I've tested on Win NT and QNX > > > Is there a bug or am i doing something wrong? > Thanks in advance, -- Brent Welch <bre...@in...> http://www.interwoven.com |