Subject: CCL:Uploading PDB files to a CGI script

From: "Robert Fraczkiewicz" <[email-masked]>
Date: Tue, 23 Jun 1998 18:27:45 -0500

Dear Netters:

Thanks to all who replied to my inquiry. In my original posting I have
reported a web server timing out when large files are uploaded via an
HTML form.

After some wrestling with the script I have figured out that the web
server is basically OK and can accept data of any size. The problem is
with Netscape browsers: server times out because browsers cannot handle
large amounts of data from CGI programs. Let me present an example:

This simple HTML form will let you upload any readable disk file into
a CGI program:

<HTML>
<HEAD>
<TITLE>Simple form</TITLE>
<BODY>
<FORM ENCTYPE="multipart/form-data" METHOD="POST" ACTION="your_CGI_script">
 Enter PDB file name:<BR>
<INPUT TYPE="file" NAME="pdbdata" SIZE=70></INPUT>
<P>
<INPUT NAME="s_submit" TYPE="SUBMIT" VALUE="SUBMIT"></INPUT>
<INPUT NAME="s_reset"  TYPE="RESET"  VALUE="RESET FORM"></INPUT>
</FORM>
</BODY>
</HTML>

The CGI program I used takes the data and returns it to the browser
as plain text (compile it and replace "your_CGI_script" by the executable
pathname):

#include <stdio.h>
#include <stdlib.h>

main()
{
    unsigned long i, n=0;
    char *cl;

    printf("Content-type:text/plain\n\n");
    cl=getenv("CONTENT_LENGTH");
    if(cl) n=atoi(cl);

    for(i=0; i<n; i++) putchar(getchar());
    putchar('\n');
    fflush(stdout);
}

This works fine for small input files. For PDB data the threshold correspond
to about ~300 atom coordinates. Submitting larger file locks the browser
and causes the server to time out. When the "putchar" function is removed
>from the "for" loop (i.e., no data are returned to the browser) everything
works fine. Same when the loop is slightly modified to output characters
for "i" below certain threshold (10000 works here). Clearly, there is a
miscommunication between the CGI program and the browser.

I tried Netscape 3.04 and 4.02 on SGI, Netscape 3.0 on PC and Netscape 4.02 on
Apple Macintosh. All of them show the same symptoms. Is it a bug, or am I doing
something wrong? Any hints will be greatly appreciated and summarized on the
list.

With best regards,
Robert Fraczkiewicz
University of Texas Medical Branch