CGI.pm to the rescue. Files uploaded via the CGI upload form element create a temporary file on your system already (this is a CGI.pm behavior). The file is automatically unlinked when the script cleans up after itself (behind the scenes). The canonical way to handle uploads is to immediately save them to your own explicit file. But in your case, you're looking for a way to avoid saving the file explicitly. Fortunately, CGI.pm allows you to access the temp file directly. See the following, clipped from the CGI.pm documentation:

When processing an uploaded file, CGI.pm creates a temporary file on your hard disk and passes you a file handle to that file. After you are finished with the file handle, CGI.pm unlinks (deletes) the temporary file. If you need to you can access the temporary file directly. You can access the temp file for a file upload by passing the file name to the tmpFileName() method:

$filename = $query->param('uploaded_file'); $tmpfilename = $query->tmpFileName($filename);

The temporary file will be deleted automatically when your program exits unless you manually rename it. On some operating systems (such as Windows NT), you will need to close the temporary file's filehandle before your program exits. Otherwise the attempt to delete the temporary file will fail.

So what you could do is allow a file upload, and then process the file in-script without ever saving it explicitly to disk. Be sure to limit the upload file size to something reasonable by setting $CGI::POST_MAX to a value that is large enough for your needs, and small enough to prevent Denial of Service Attacks. Also please remember that any script running via a webserver is potentially running many instances at the same time (Apache forks off multiple processes to accommodate many clients simultaneously). So any memory usage your script creates could potentially be multiplied by the number of site users hitting your script at the same time. The result could be that a script which is already a memory hog, when multiplied by a few instances, could create a real problem on your server. That's one reason why it's common practice to keep large data in files or in a database rather than dealing with them entirely in memory.


Dave


In reply to Re: Cgi params as binary data by davido
in thread Cgi params as binary data by atey1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.