Incorrect filename on WWW::Mechanize submission
Asked Answered
E

1

6

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?

Euphemia answered 2/10, 2011 at 15:22 Comment(5)
I did a test and got filename="ARRAY(0x1f124d8)" too, dumping $mech->res ( WWW::Mechanize 1.66 ).Fury
Does a key of "with_fields" instead of "fields" yield a different result? "with_fields" would help if there is more than one form and no form has been selected.Exhume
with_fields gave the same result as fields.Ascites
That looks really similar to the LWP base field submission (c/f lwp.interglacial.com/ch05_07.htm). Does submitting fields => {'UploadedFile' => [ undef, 'test2.txt', Content => $content ], upload_field => 1 }, where upload_field is the name of the form submission field, work correctly?Gregorio
@Oesor: I'm unsure as to what you want me to write instead of upload_field?Ascites
I
2

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;
Indecorum answered 4/10, 2011 at 12:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.