Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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 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.

Comment on File Upload Frustration
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://967222]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2014-11-28 00:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (191 votes), past polls