http://www.perlmonks.org?node_id=11110773


in reply to Re^3: File upload w/WWW::Mechanize
in thread File upload w/WWW::Mechanize

With recent versions of WWW::Mechanize (only tried 1.91 or later), there is a simpler solution:

$response = $mech->submit_form( with_fields => { 'filechooserelement' => [ [ $tmpfile, $uploadfile ], 1 ], ... , }, );

Where tmpfile is the pathname to the file in your file system, and uploadfile is the filename that will be given in the in the multipart request to the server (be sure to never include a path here). WWW::Mechanize takes care of whether it's a PUT or POST, etc. filechooserelement must be a form field of type file to trigger this behaviour, of course.