As far as I can read from the WWW::Mechanize documentation, you can do the following to submit a file from a string:
$mech->submit_form(
fields => {
'UploadedFile' => [[ undef, 'test2.txt', Content => $content ], 1],
}
);
This should submit a file with name text2.txt
, containing the text in $content
(in this case, 'The file is a lie.'
).
The request failed with an internal server error, however, so I examined the request that was sent, and found this:
--xYzZY
Content-Disposition: form-data; name="UploadedFile"; filename="ARRAY(0x9567570)"
The file is a lie.
--xYzZY
That is clearly not the filename I specified, so I wonder: Am I doing something wrong, or is the module bugged?
This is a bug in HTML::Form. I have reported it to the author.
In the mean time, if you have HTML::Form version 6.00, you can fix things temporarily by commenting out line 1442 in HTML/Form.pm which reads
$old = $self->file unless defined $old;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With