Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

File Upload Frustration

by jcinsd (Initiate)
on Apr 26, 2012 at 03:12 UTC ( #967222=perlquestion: print w/replies, xml ) Need Help??
jcinsd has asked for the wisdom of the Perl Monks concerning the following question:

This should be a simple one. I am using 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.


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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://967222]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2018-06-25 19:53 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (128 votes). Check out past polls.