Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: File upload w/WWW::Mechanize

by jczeus (Monk)
on Mar 11, 2016 at 14:16 UTC ( #1157436=note: print w/replies, xml ) Need Help??


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

It did!

Just ran into the same problem. Your solution still works.

But isn't there another solution? Why do I have to reach into the innards of $agent to specify the file path, the submitted filename and the content type?

This would be a nice candidate for the cookbook.

Replies are listed 'Best First'.
Re^3: File upload w/WWW::Mechanize
by Anonymous Monk on Mar 12, 2016 at 00:11 UTC

      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.

        WWW::Mechanize takes care of whether it's a PUT or POST, etc

        Hi

        PUT is a HTTP method, and its one not supported by html forms. Mechanize submit_form doesn't support it either since HTML::Form doesn't. HTML::Form simply passes along upload filename to LWP family (see link above). LWP (HTTP....) does not support multipart/form-data for PUTs , only for POSTS....

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1157436]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2021-11-30 13:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?