From: Anders N. <an...@di...> - 2001-01-26 13:11:07
|
Hi. I'm trying to implement a file uploadpage with cgi. I've taken a look at the demo that comes with the tclhttpd, especially the testupload.tml file. For me, since I don't really get the .tml workings, the main part of recieving the uploaded file is this: foreach {n v} [ncgi::nvlist] { append html [html::row $n [html::tableFromList [lindex $v 0]]] append html [html::row $n [ncgi::value $n]] append html <tr>[html::cell "colspan=2" "<pre>[html::quoteFormValue [lindex $v 1]]</pre>"]</tr> } which nicely breaks down to: foreach {n v} [ncgi::nvlist] { append html "name: $n " append html "value: $v " } for the sake of clarity. Now, that works just fine, but when I try to put that into my own ncgitest.cgi file, it doesn't work as in the .tml file above. When I run my own cgi-script, I don't get any values in the $n variable, and in the $v variable I get the whole thing. Ie. the .tml file gives these values: $n: hide_me $v: {content-disposition form-data name hide_me} {hello, world} while my cgi-file gives these values: $n: <empty> $v: {} {Content-Disposition: form-data; name="hide_me" hello, world } Also, when I try to upload a little bigger imagefile the .tml version handles it nicely, but my cgi-file just hangs... What am I doing wrong, or what is the .tml version doing that I don't? /Anders N |
From: Brent W. <bre...@in...> - 2001-01-27 01:33:53
|
>>>"Anders Nilsson" said: > Hi. > > I'm trying to implement a file uploadpage with cgi. I've taken > a look at the demo that comes with the tclhttpd, especially the > testupload.tml file. For me, since I don't really get the .tml > workings, the main part of recieving the uploaded file is this: > > foreach {n v} [ncgi::nvlist] { > append html [html::row $n [html::tableFromList [lindex $v 0]]] > append html [html::row $n [ncgi::value $n]] > append html <tr>[html::cell "colspan=2" "<pre>[html::quoteFormValue > [lindex $v 1]]</pre>"]</tr> > } > > which nicely breaks down to: > > foreach {n v} [ncgi::nvlist] { > append html "name: $n " > append html "value: $v " > } > > for the sake of clarity. Now, that works just fine, but when I > try to put that into my own ncgitest.cgi file, it doesn't work > as in the .tml file above. When I run my own cgi-script, I don't > get any values in the $n variable, and in the $v variable I get > the whole thing. The differences below seem to indicate that the CGI case isn't correctly detecting the multipart/ content type. The ncgi:: package does some extra work for you in this case to unbundle the arguments as you can see. You should print out the $env(CONTENT_TYPE) in your CGI - perhaps TclHttpd isn't passing through the right thing. > Ie. the .tml file gives these values: > $n: hide_me > $v: {content-disposition form-data name hide_me} {hello, world} > > while my cgi-file gives these values: > $n: <empty> > $v: {} {Content-Disposition: form-data; name="hide_me" hello, world } > > Also, when I try to upload a little bigger imagefile the .tml version > handles it nicely, but my cgi-file just hangs... This bug was recently diagnosed. You can either backtrack to 3.2 from 3.2.1, or use the attached cgi.tcl and doc.tcl files. The fix is only in cgi.tcl, but it uses a new API provided by doc.tcl for other reasons. I'll put out a 3.2.2 "soon", but I can't say just when I'll get to it. Actually, but real bug is in Tcl's fcopy command - the 3.2.1 version of cgi.tcl switched to using fcopy in a certain case that exposed the fcopy bug. That bug has also been diagnosed. Thanks to Don Porter for all that sleuthing! These files are up-to-date in CVS. -- Brent Welch <bre...@in...> http://www.interwoven.com |
From: Anders N. <an...@di...> - 2001-01-29 16:19:20
|
Brent Welch: > You should print out the $env(CONTENT_TYPE) > in your CGI - perhaps TclHttpd isn't passing through the right thing. I wrote a little snippet: puts "Content-Type: text/html" fconfigure stdin -translation {binary binary} set sinput [read stdin $env(CONTENT_LENGTH)] puts -nonewline $sinput If I run that cgi-program and uploads a, say a GIF-file, and compares the output with when I upload the same file with the tclhttpd example testupload.tml, I don't get exactly the same result... The differences in the result is visible below: My cgi-test from above: GIF89a ?yu?U?,3??aC$c!????????Z?????????~}|vutrqonkjih<kaschnip> The output from testupload.tml: GIF89a ?yu?U?,3??aC$c!?s~--"'?Z?OS^?."f,~}|vutrqonkjih<kaschnip> As we see, my version has some trouble with certain characters, why I ask you. How shall I configure my cgi-script to read those characters correctly? /Anders N |
From: Brent W. <bre...@in...> - 2001-01-29 21:13:39
|
Which one is correct? Make sure your stdin is in binary mode: fconfigure stdin -trans binary in your CGI version. >>>"Anders Nilsson" said: > Brent Welch: > > You should print out the $env(CONTENT_TYPE) > > in your CGI - perhaps TclHttpd isn't passing through the right thing. > > I wrote a little snippet: > > puts "Content-Type: text/html" > fconfigure stdin -translation {binary binary} > set sinput [read stdin $env(CONTENT_LENGTH)] > puts -nonewline $sinput > > If I run that cgi-program and uploads a, say a GIF-file, > and compares the output with when I upload the same file > with the tclhttpd example testupload.tml, I don't get > exactly the same result... > > The differences in the result is visible below: > > My cgi-test from above: > GIF89a ?yu?U?,3??aC$c!????????Z?????????~}|vutrqonkjih<kaschnip> > > The output from testupload.tml: > GIF89a ?yu?U?,3??aC$c!?s~--"'?Z?OS^?."f,~}|vutrqonkjih<kaschnip> > > As we see, my version has some trouble with certain characters, > why I ask you. How shall I configure my cgi-script to read those > characters correctly? > > /Anders N > > > _______________________________________________ > TclHttpd-users mailing list > Tcl...@li... > http://lists.sourceforge.net/lists/listinfo/tclhttpd-users -- Brent Welch <bre...@in...> http://www.interwoven.com |
From: Brent W. <bre...@in...> - 2001-01-29 21:14:21
|
By the way, I've started work on a file upload domain handler for TclHttpd, but it'll probably take me a few days to get through it. >>>"Anders Nilsson" said: > Brent Welch: > > You should print out the $env(CONTENT_TYPE) > > in your CGI - perhaps TclHttpd isn't passing through the right thing. > > I wrote a little snippet: > > puts "Content-Type: text/html" > fconfigure stdin -translation {binary binary} > set sinput [read stdin $env(CONTENT_LENGTH)] > puts -nonewline $sinput > > If I run that cgi-program and uploads a, say a GIF-file, > and compares the output with when I upload the same file > with the tclhttpd example testupload.tml, I don't get > exactly the same result... > > The differences in the result is visible below: > > My cgi-test from above: > GIF89a ?yu?U?,3??aC$c!????????Z?????????~}|vutrqonkjih<kaschnip> > > The output from testupload.tml: > GIF89a ?yu?U?,3??aC$c!?s~--"'?Z?OS^?."f,~}|vutrqonkjih<kaschnip> > > As we see, my version has some trouble with certain characters, > why I ask you. How shall I configure my cgi-script to read those > characters correctly? > > /Anders N > > > _______________________________________________ > TclHttpd-users mailing list > Tcl...@li... > http://lists.sourceforge.net/lists/listinfo/tclhttpd-users -- Brent Welch <bre...@in...> http://www.interwoven.com |