nosbod has asked for the wisdom of the Perl Monks concerning the following question:

hi,

i'm trying to upload files with a form using WWW::Mechanize. The form looks like this:

<p><form enctype="multipart/form-data" action="upload.cgi" method="pos +t"> <p><b><u><font face="Arial,Helvetica"><font size=+1> To run a detailed ssSNPer analysis on a single SNP:</font></font></u></b> <p><font face="Arial,Helvetica">Specify the location of your file containing the test SNP rs# (e.g., "<a href="http://fraser.qimr.edu.au/general/da +leN/ssSNPer/rs1800630snp.txt">rs1800630snp.txt</a>"):</font> <br><input name="testSNP" type="file"> <p><font face="Arial,Helvetica">Specify the location of your HapMap SN +P genotype data dump file (e.g., "<a href="http://fraser.qimr.edu.au/gen +eral/daleN/ssSNPer/rs1800630dumpedregion.txt">rs1800630dumpedregion.t +xt</a>"):</font> <br><input name="HapMapData" type="file"> <p><font face="Arial,Helvetica">Please be patient, our web server may +be busy and depending upon the size of your test region your query may ta +ke a few minutes (the example files take ~90 seconds).</font> <br><input type="submit"> </form>
the piece of code i'm using looks like this:
$mech->get( "http://fraser.qimr.edu.au/general/daleN/ssSNPer/" ); $mech->form_number(1); $mech->field("testSNP"=>"/tmp/hapmap/rs11581638_name.txt"); $mech->field("HapMapData"=>"/tmp/hapmap/rs11581638_data.txt"); my $request=$mech->submit(); my $content=$request->content; print $content;
Anyone any ideas why this isn't working?

ta

Replies are listed 'Best First'.
Re: WWW::Mechanize and file upload
by ferreira (Chaplain) on Jan 05, 2007 at 18:16 UTC
    Anyone any ideas why this isn't working?

    I doubt. How is it not working? Does it die? Does it not do what you want? And what you expect on a successful run?

    First random hint: let WWW::Mechanize do the testing of results for you (as you're not checking anything right now). That can be done with:

    $mech = WWW::Mechanize->new(autocheck=>1);

    Second and last random hint: read the documentation (WWW::Mechanize) carefully and thoroughly.

      the page that is returned states that the file was not uploaded correctly. It states that the file my be in the wrong format or that there was a problem with the upload. It's not in the wrong format, i've tried it manually, it's fine.

      is there an obvious error with the code? the docs don't really talk about file uploads. i assume it can be done but the docs aren't particularly specific toher than the sentence:

      "If the field is of type file (file upload field), the value is always cleared to prevent remote sites from downloading your local files. To upload a file, specify its file name explicitly."

Re: WWW::Mechanize and file upload
by Anonymous Monk on Jan 06, 2007 at 04:28 UTC
    Turn on debugging
Re: WWW::Mechanize and file upload
by f00li5h (Chaplain) on Jan 07, 2007 at 04:23 UTC

    Another random hint: try submitting this form to a CGI script of your own design, one that will belch out the contents of the form.

    It may very well be that you're just submitting the text "/tmp/hapmap/rs11581638_name.txt" in the field instead of the contents of the file... you may need to slurp the file and submit that  do{local $/; open $f,'>','/tmp/...';<$f>} or similar.

    Ofcourse it's just a guess

    @_=qw; ask f00li5h to appear and remain for a moment of pretend better than a lifetime;;s;;@_[map hex,split'',B204316D8C2A4516DE];;y/05/os/&print;