Hi, Monks

I have some weird problem while uploading file with Cyrillic name via WWW::Mechanize. The file is uploaded correctly but the name is broken (I see only ?????? on the target site).

The code is simple:

use WWW::Mechanize; use Encode qw(from_to); my $config = { login => "login", password => "pass", source_folder => "$Bin/source_folder", }; my $mech = WWW::Mechanize->new( autocheck => 1 ); $mech->agent_alias("Windows IE 6"); $mech->get("http://www.antiplagiat.ru/Cabinet/Cabinet.aspx?folderId=68 +9935"); authorize($mech); $mech->submit_form( form_number => 1, fields => {}, button => 'ctl00$ctl00$Body$MainWorkSpacePlaceHolder$FolderControl_StdFolder_0$D +ocumentsGrid$btnAddItem', ); find( \&wanted, $config->{source_folder} ); sub wanted { return unless -f; say $config->{source_folder} . "/" . $_; #from_to($_, "CP1251", "UTF8"); doesn't work too :-( my $mech = $mech->clone(); $mech->submit_form( form_number => 1, fields => { 'ctl00$ctl00$Body$MainWorkSpacePlaceHolder$fuDocumentUploa +d' => $config->{source_folder} . "/" . $_, }, button => 'ctl00$ctl00$Body$MainWorkSpacePlaceHolder$btnCommit +Upload', ); }

If I encode file name from CP1251 to UTF8 than upload doesn't work... Please help me to find solution.

Update:

Here is solution I use (File upload w/WWW::Mechanize)

my $filename = $_; from_to( $filename, "CP1251", "UTF8" ); my $mech = $mech->clone(); my $form = $mech->form_number(1); $mech->field( 'ctl00$ctl00$Body$MainWorkSpacePlaceHolder$fuDocumen +tUpload', $config->{source_folder} . "/" . $_ ); $form->find_input( 'ctl00$ctl00$Body$MainWorkSpacePlaceHolder$fuDocumentUpload')- +>filename($filename); $mech->submit_form( form_number => 1, button => 'ctl00$ctl00$Body$MainWorkSpacePlaceHolder$btnCommit +Upload', );

In reply to WWW::Mechanize uploaded file name problem by Gangabass

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.