Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^9: Combining Ffile:fetch with MySQL

by justin423 (Scribe)
on Jul 25, 2022 at 15:06 UTC ( [id://11145712]=note: print w/replies, xml ) Need Help??


in reply to Re^8: Combining Ffile:fetch with MySQL
in thread Combining Ffile:fetch with MySQL

it is a windows machine and it is in the C:\ directory. so C:\data\ is the path. to test that, I updated it to download to both /data/ and a new subdirectory called: /data/documents/ changed it to this:
#$path='/data/'; $path= '/data/documents/'; while (my $ref = $query->fetchrow_hashref()) { print "url: $ref->{url}\n"; my $ff = File::Fetch->new(uri=>$ref->{url}); my $where = $ff->fetch( to => '$path'); my $error= $ff->error(); print $error;
and the output is the same. no error messages. changing it from print $error to print $ff, I get the link followed by: File::Fetch=HASH(0x30d2a18)

Replies are listed 'Best First'.
Re^10: Combining File::Fetch with MySQL
by hippo (Bishop) on Jul 25, 2022 at 15:47 UTC
    my $where = $ff->fetch( to => '$path');

    Again, you are enclosing a variable inside single quotes, so it won't be interpolated. Remove the quotes for more success.

    Here is an SSCCE showing how to use File::Fetch successfully.

    #!/usr/bin/env perl use strict; use warnings; use File::Fetch; use Test::More tests => 1; my $url = 'https://www.perlmonks.org/?part=1;displaytype=displaycode;n +ode_id=11145569;abspart=1'; my $ff = File::Fetch->new (uri => $url); my $loc = $ff->fetch (to => '/tmp/'); ok -f $loc, "Downloaded file to $loc";

    Try examining the return value of fetch like this in your code to find the saved file.


    🦛

      "Success"!!! ok, I got it to work for one file and when doing it for the 2nd file, it overwrote the first, because all the files are named "document.pdf". so I updated it to this, which isn't ideal. I would rather use the field document_id in the database instead of just getting back document0.pdf document1.pdf document2.pdf
      $i=0; while (my $ref = $query->fetchrow_hashref()) { print "url: $ref->{url}\n"; my $ff = File::Fetch->new(uri=>$ref->{url}); my $where = $ff->fetch( to => '/data/documents/'); my $error= $ff->error(); rename ("C:/data/documents/document.pdf","C:/data/documents/documen +t$i.pdf"); ($i++); }
      the other website I tried it on gave me a nasty gram of "Unable to Respond to this Request" "contact the helpdesk" But this will work for now.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11145712]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-18 19:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found