Uploading multiple files using LWP

Simon Wistow simon at thegestalt.org
Tue Aug 10 08:06:41 BST 2010


On Tue, Aug 10, 2010 at 07:38:33AM +0100, me said:
> I want to POST multiple files to an API endpoint. 

Once again proving that debugging to teddy^W mailing list works ...

Instead of

  $req = POST($url, Content_Type => 'form-data', Content => [%opts]);

I had to do

  my @content;
  foreach my $key (keys %opts) {
    my $value = $opts{$key};
    $value    = [$value] unless ref($value);
    foreach my $v (@$value) {
      $v = [$v] if $is_file_param{$key};
	  push @content, ($key, $v);
    }
  }
  $req  = POST($url, Content_Type => 'form-data', Content => \@content);

et viola - it all worked.




More information about the london.pm mailing list