perlcgipostdata

How to upload a file from POST request. CONTENT_TYPE: application/octet-stream. Perl


I get a POST request with

CONTENT_TYPE: application/octet-stream

I get all data like this

my $cgiQuery = CGI->new() or die();
my $cgiData = $cgiQuery->Vars;

my $getQuery = CGI->new($ENV{QUERY_STRING});
my $getData = $getQuery->Vars;

foreach my $getKey(keys %{$getData})
{
    $cgiData->{$getKey} = $getData->{$getKey};
}

my $data = $cgiQuery->param('POSTDATA');

But when i try to print it

print Dumper($data) ."\n";
print Dumper($cgiData) ."\n";

I get this:

$VAR1 = 'type=catalog&mode=file&filename=offers0_14.xml';

$VAR1 = {
      'POSTDATA' => 'type=catalog&mode=file&filename=offers0_14.xml',
      'session' => 'aa4979ad18f64e4d959dd16444cee5fd'
    };

How can i get and upload file filename=offers0_14.xml to the server?


Solution

  • The solution is next, That POSTDATA is binary file. So, i got that file by this code

    my $file_cgi = CGI->new($ENV{POSTDATA});
    my $file = $file_cgi->Vars;
    
    my $filename = path_to_the_file_on_the_server;    
    open (OUTFILE,"> $filename");
    print OUTFILE $file->{POSTDATA};
    close OUTFILE;