Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Image Magick using Net FTP

by Mission (Hermit)
on May 22, 2002 at 14:54 UTC ( [id://168449]=perlquestion: print w/replies, xml ) Need Help??

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

Fellow monks,

I am too close to this situation to see the solution clearly, therefore I seek the wisdom...

The Goal:
  • Utilizing a CGI upload, a user can browse to a picture, select a picture, upload it to the destination server (not the CGI server) while Image Magick resizes and renames the picture appropriatley.


  • The Environment:
  • There are three machines, client, CGI server (W2K-Apache), Destination Web server (Open VMS).
  • Note: The CGI server is limited on hard drive space.


  • Achieved so far:
  • CGI upload of the file to the destination server (not the CGI server).
  • Image Magick resizing and renaming, but only writing to the CGI server.


  • Problem:
  • $image->Write($filename); writes to the CGI server, and not to the destination web server.
  • $ftpSession->put($image->Write($filename),$filename); writes to both servers. The destination server has the full version image, where the CGI server has the resized and renamed image (obvious error here.)
  • $ftpSession->put($image,$filename); errors out stating: "Not a GLOB reference"


  • I've tried many variations of the 'put', but it seems that nothing is working. I want to bypass the CGI server completely and move the resized file driectly to the destination server.

    I seek wisdom...

    - Mission

    Replies are listed 'Best First'.
    Re: Image Magick using Net FTP
    by giulienk (Curate) on May 22, 2002 at 16:50 UTC
      I try a solution: untested code ahead.
      use IO::File; my $fh = IO::File->new_tmpfile; $image->Write(file => $fh); seek($fh, 0, 0); $ftpSession->put($fh, $filename);
      The temporary file will be erased as you close it. It's in someway as it never existed and it's just useful to pass a filehandle to the Net::FTP put method instead of a scalar (that the method doesn't accept).


      $|=$_="1g2i1u1l2i4e2n0k",map{print"\7",chop;select$,,$,,$,,$_/7}m{..}g

    Re: Image Magick using Net FTP
    by joealba (Hermit) on May 22, 2002 at 15:21 UTC
      Could you process the images on the CGI server, FTP all the images to the destination server, then delete them from the CGI server? Is the drive space THAT limited?

      Granted, it's not as elegant as printing filehandles over Net::FTP, but it gets the job done.

        That is an option that I have considered, but the web application could have two people uploading 'potentially' the same filename to different destinations on the destination web server. So there is a potential of 'accidentially' overwriting someone else's image when it hits the CGI server.

        I may have to do that (and develop some unique names to avoid the confilcts) but I still believe that this procedure has to be possible. With Perl all things are supposed to be possible... perhaps this is a limitation of Image Magick, but their web site (http://www.imagemagick.org/www/perl.html) doesn't reveal a solution.

        - Mission
    Re: Image Magick using Net FTP
    by Mission (Hermit) on May 23, 2002 at 13:47 UTC
      First off thanks to joealba and giulienk for your guidance.

      I believe that giulienk's logic is correct, and it seems to be right on. However it appears that Image Magick doesn't like to write to a temp file (at least in a W2K environment.) So after fighting with it for a long while, I finally gave up on the challenge for now. Perhaps I'll take this torch up at a later time. Therefore I did do what joealba suggested for a fix. I knew that would work, but it still seems like a hack. If someone ever does find a solution, please \msg me. Thanks.

      - Mission

    Log In?
    Username:
    Password:

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

    How do I use this?Last hourOther CB clients
    Other Users?
    Others sharing their wisdom with the Monastery: (9)
    As of 2024-03-28 12:25 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found