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

Hi

Thanks for your previous help with this everybody but I still can't get this to work. I want to POST a file to a https server. GET is working fine.

This is the form on the server:

<form action="https://<address>/cgi-bin/upload.pl" method="post" encty +pe="multipart/form-data"> <input type="File" name="FILE1" size="40"> <input type="File" name="FILE2" size="40"> <input type="File" name="FILE3" size="40"> <input type="File" name="FILE4" size="40"> <input type="File" name="FILE5" size="40"> <input type="File" name="FILE6" size="40"> <input type="File" name="FILE7" size="40"> <input type="File" name="FILE8" size="40"> <input type="File" name="FILE9" size="40"> <input type="File" name="FILE10" size="40"> <input type="Submit" value=" Upload " > <input type="reset" value=" R +eset ">

This is my code (I have tried many variations of this):

my $url = 'https://<address>/cgi-bin/upload.pl'; my $response = $browser->post($url,Content_Type => "multipart/form-data" Content => [file => ['data.txt']]); print ($response->status_line);

I get an "OK" response but the file never gets to the server. Can you see anything wrong?

Thanks

Jonathan

Edited by Chady -- added code tags around form.

Replies are listed 'Best First'.
Re: How do I upload a file to a https server?
by sacked (Hermit) on Jun 07, 2004 at 17:06 UTC
    file is not the name of any of the form fields listed in the HTML you posted. If you are trying to send a file through the FILE1 form field, for example, you need to change the field name passed to the Content portion of the call to $browser->post():
    my $response = $browser->post( $url, Content_Type => "multipart/form-data", Content => [FILE1 => ['data.txt']] );

    --sacked
Re: How do I upload a file to a https server?
by meetraz (Hermit) on Jun 07, 2004 at 17:07 UTC
    Jonathan, I think what you want is something like this:
    (make sure data.txt is in the local directory, or specify the full path)
    use strict; use LWP::Useragent; use HTTP::Request::Common; my $ua = new LWP::UserAgent; my $res = $ua->request(POST 'https://<address>/cgi-bin/upload.pl', Content_Type => 'form-data', Content => [ foo => 'bar', bar => 'baz', FILE1 => ["data.txt"], ] );
    update: Changed file field name.
      Thanks guys - it's working. I tried using the form field 'File1' yesterday but did not realise it was case sensitive. FILE1 works.

      Thanks.

      Jonathan.