"petersm" <[EMAIL PROTECTED]> writes:
> Gisle Aas wrote,
> > "petersm" <[EMAIL PROTECTED]> writes:
> >
> > > I am new to LWP and WWW::Mech and have used them on a couple of
> > > projects. I was wondering what is the best way to do a multipart
> > > post (file upload) using LWP.
> >
> > >From LWP you just do a post with something like:
> >
> > $ua->post('http://www.example.com',
> > content_type => 'form-data',
> > content => [
> > foo => 1,
> > file => ["foo.txt"],
> > ]);
> >
> > More details available by reading the HTTP::Request::Common manpage.
>
> Thanks Gisle. Great work BTW. Ok, so if I understand this correctly, if I want
> to upload a file but I have the contents of that file in a scalar then I can
> do something like this...
>
> $ua->post('http://www.example.com',
> content_type => 'form-data',
> content => [
> foo => 1,
> file => [undef, '', $my_files_contents],
> ]);
>
> Is this correct? Thanks,
About right. You probably want to give it a name, i.e. replace the ''
with something else. If you construct the response with POST you
might inspect it directly like this:
use HTTP::Request::Common qw(POST);
print POST('http://www.example.com',
content_type => 'form-data',
content => [
foo => 1,
file => [undef, 'foo.txt', $my_files_contents],
])->as_string;
then tweak until you are happy.
--Gisle