This should be a simple one. I am using CGI.pm to upload files to the server and all works for the JPGs. However, for some reason, the equivalent code for PDFs fails. My apache error log gives a "Malformed multipart POST: data truncated" and I have seen this cited elsewhere. Again, the same thing works for the image files in parallel code.

The form is simple:

<form enctype="multipart/form-data" method="post" action="xxxxx"> <input type="file" accept="application/pdf" name="file"> <input type="submit" value="Upload"> </form>

(xxxxx is just hiding the actual script name.)

For jpgs, I have this, and it works:

<form enctype="multipart/form-data" method="post" action="yyyyy"> <input type="file" accept="image/jpg" name="file"> <input type="submit" value="Upload"> </form>

It is processed with:

my $cgi = new CGI; my $file = new $cgi->param('file'); open(FUP,">$vdir$fn"); while (<$file>) { print FUP $_; } close FUP; print $cgi->header();

The only real difference for the JPG uploader for that is that there is a size restriction placed on the file with:

$CGI::POST_MAX = 1024 * 1024;

I do not have that at all for the PDFs. Is "application/pdf" incorrect or do I have to make some other accommodation? This has to be a SMH simple thing, but eludes me.

Thanks, in advance, for any assistance.

One thing that did occur to me is the possibility of a buffer limitation in the post. I have bumped up against that for $ENV{'CONTENT_LENGTH'} before.

UPDATE - SOLVED

I'll keep this here with the solution in case someone else faces the same thing.

sysread(STDIN, $inputdata, $ENV{'CONTENT_LENGTH'});

Don't need to do this, unlike in ordinary form post processing. Leave that out and it works like a charm.


In reply to File Upload Frustration by jcinsd

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.