jkenneth has asked for the wisdom of the Perl Monks concerning the following question:
Content-Disposition: form-data; name="file"; filename="file.1" Content-Type: application/octet-stream
However via Mech they send:
Content-Disposition: form-data; name="file"; filename="/tmp/file.1" Content-Length: 1056 Content-Type: application/x-troff-man
While reading the docs I found how to do it using HTTP::Request::Common, so after digging I tried to get the following to work:
use WWW::Mechanize 0.63; use WWW::Mechanize::FormFiller; $agent = WWW::Mechanize->new(); $agent->get("http://moonwolf/file2.html"); $agent->form_name('put_form'); $agent->field('file', ["/tmp/file.1", 'myFilename', ['Content-Type' => 'application/octect-stream']], 1); $agent->click();
Unfortunately, this causes the filename to become an array reference.
I tracked down the name to HTML::Form::FileInput where it has a reference to a 'legacy' section of code, which when I added
$filename = $fn if (ref($filename));
fixed the issue.
Is there another way to do this using WWW::Mechanize? I'd rather not have my change get whacked if someone decides to update LWP in the future.
JK
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File upload w/WWW::Mechanize
by Corion (Patriarch) on Oct 30, 2003 at 16:57 UTC | |
|
Re: File upload w/WWW::Mechanize
by jkenneth (Pilgrim) on Oct 31, 2003 at 17:49 UTC | |
by jczeus (Monk) on Mar 11, 2016 at 14:16 UTC | |
by Anonymous Monk on Mar 12, 2016 at 00:11 UTC | |
by c-alpha (Novice) on Dec 30, 2019 at 17:16 UTC | |
by Anonymous Monk on Dec 30, 2019 at 19:23 UTC |