Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,


I tried to post the binary file from standalone perl script using LWP::Simple::Post module and the binary file size is nearly 2MB.
But in the server, i got only 23KB (approx).
How can i increase the content-length while posting? How can i post the binary file without any data loss? Is there any alternative modules?
Thanks in advance

Replies are listed 'Best First'.
Re: How to change content-length in CGI
by dHarry (Abbot) on Jan 05, 2009 at 12:55 UTC

    How can i increase the content-length while posting?

    Can't you set it? With something like:

    $request->header('Content-Length', "$the_length");

    Check the http specs for the correct usage of content-length, i.e. apparently decimal number of OCTETs.

    Also see: sending a large file via http.

    HTH,
    dHarry

Re: How to change content-length in CGI
by MidLifeXis (Monsignor) on Jan 05, 2009 at 12:21 UTC

    This wouldn't be, perhaps, a Windows server, would it?

    Check out binmode and see if it helps.

    --MidLifeXis

      More than likely, the code setting the content length is getting hosed *because* there's a null in the data stream. I think LWP::Simple::Post is probably the wrong module to upload a file. You're probably better off using LWP::UserAgent directly.

      -derby
Re: How to change content-length in CGI
by linuxer (Curate) on Jan 05, 2009 at 12:11 UTC

    Hi, are you seeking for help for the sending client script or for the receiving server script?

    Some code would be helpful, so one knows how you do it.

      Standalone script

      #!/usr/bin/perl use strict; use warnings; use LWP::Simple::Post qw(post); #binary file open(FH, "binaryfile"); my $Data = do{local $/; <FH>}; close(FH); my $url = 'http://localhost:8080/cgi-bin/index.pl'; my $content = post($url, $Data); print $content;

      Server script

      #!/usr/bin/perl use strict; use CGI; my $q = new CGI; print "\nMethod :", $ENV{REQUEST_METHOD}; print "\nContent_Length : ", $ENV{CONTENT_LENGTH}; #binary file open (FH, ">binaryoutput"); print FH $q->param() if ($q->param()); close(FH);

      In the server script, i need to do several process and also i don't want to upload concept. For some concept, I want to post the data and retrive in the server look like parameters

        Could this be another binmode issue? Try adding a binmode FH right after opening your file. You could also print out the length of $Data right before you post it to make sure it's the size you're expecting.