perlquestion
jkenneth
I'm trying to use Mech to automate a file upload, however I'm seeing some odd behavior. When I execute the upload via the browser the params are:
<p>
Content-Disposition: form-data; name="file"; filename="file.1" Content-Type: application/octet-stream
<p>
However via Mech they send:
<p>
Content-Disposition: form-data; name="file"; filename="/tmp/file.1" Content-Length: 1056 Content-Type: application/x-troff-man
<p>
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:
<p><code>
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();
</code>
<p>
Unfortunately, this causes the filename to become an array reference.
<p>
I tracked down the name to HTML::Form::FileInput where it has a reference to a 'legacy' section of code, which when I added
<p>
<code>
$filename = $fn if (ref($filename));
</code>
<p>
fixed the issue.
<p>
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.
<p><p>
JK