At 23:04 +0800 2007/01/21, bill lam wrote:
Anyone know what the cgi standard say or major http servers do
regarding cgi stdin buffer?
Suppose I post a large block of data, that data should be passed as
stdin for cgi program. Does the http server wait until all data
uploaded before invoking the cgi program? or will it invoke the cgi
program just after header block arrived completely, so that the cgi
can read stdin as chunks of data.
--
regards,
bill
I'm not sure about what standards say, but in creating a file
uploading facility in Linux/Apache, I had troubles with large
objects via a CGI post call. As I recall, the troubles began
at only a few hundred KB - but this may have been exacerbated by
the limited size of STDIN buffers in J (much improved in J6, I
think). So I split the process into two parts. The HTML POST
that initiates the upload process calls a simple bash script e.g.
#!/bin/bash
tf=/tmp/fdat$$
cat > $tf
./pfdat $tf "$REMOTE_ADDR" "$HTTP_USER_AGENT" "$$"
which uses facilities in "cat" to manage the data flow, creates
a temporary file and then calls my j CGI script "pfdat" with
the temporary file (name) as an argument.
This seems to work quite well - pfdat returns with a complaint if
the user sends a file larger than 20 megabytes, but that is an
arbitrary limit I set to discourage users sending huge documents....
(the case that motivated me to limit it was a user with approximately
100 MSWord pages that was > 50 megabytes! :)
pfdat does things like check validity of user/password and it also
zips the uploaded data into a manageable name (getting rid of blanks
and other "noise"), sends email notification to a specified set of
users that the file has been uploaded - and finally removes the tmp
file. The email recipients can download the file conveniently by
just clicking on the url in the body of the message. Unzipping the
file after it arrives restores the original (usually Windos) name
of the document and they seem happy with the results. pfdat also
keeps activity logs that are useful in document management.
- joey
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm