Hi, Couln't you help me to figure out how to pass query string and post file content in the same request.
POST /forum/post_add.php?topic_id=20&subject=Blah&file_attach=attach where POST will contain uploaded file body. I am basically trying to inject MegaUpload progress bar written in Perl into my PHP project. So I pass my arguments from php script to perl script which handles progress bar. When finished I need to post file content to php script (to move it from temporary location) and also pass other parameters I need (topic_id, session_id, subject, message etc ) Thank you, igor "Gisle Aas" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > "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