Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Saving Photos stored in LDAP

by fritz1968 (Sexton)
on Nov 02, 2011 at 21:05 UTC ( #935491=perlquestion: print w/ replies, xml ) Need Help??
fritz1968 has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I have a simple perl script that connects to an LDAP server, searches for a user ID, then extracts the photo of that user and prints it to a file. The only problem, is that the printed file is not recognized as a photo. I believe that the file is stored in LDAP in either JPG format or HEX format. Either way, I need to print the file as a JPG. Any suggestions? Here is the code:

#open a connection to LDAP my $ldap = Net::LDAP->new ( "$idvServer" ) or die "$@"; my $result = $ldap->bind ( "$idvAdmin", password => "$idvPW", version +=> 3 ) or die($result->error()); # open the input file open WFIDS, "<$inputFile" or die("Could not open input file."); open LOGFILE, ">>$logFile" or die("Could not open log file."); foreach $empID (<WFIDS>) { chomp($empID); # remove the newline from $line. my $filter = "(workforceID=$empID)"; $mesg = $ldap->search (base => $userBase, filter => "$filter", sco +pe => "$scope", attrs => $userAttributes) ; $totalFound=$mesg->count; # determine the number of entries found, + should only be one my @entries = $mesg->entries; if ($totalFound eq 1) { my $photo = $entries[0]->get_value('photo'); open OUTFILE, ">${outputFile}${empID}.jpg" or die("Could not c +reate the empID file."); print OUTFILE "$photo"; close OUTFILE; print LOGFILE "Found 1 ID for $empID\n"; } else { print LOGFILE "Found more than 1 ID or found 0 IDs for $empID\ +n"; } } close(WFIDS); close LOGFILE; $ldap->unbind;

Comment on Saving Photos stored in LDAP
Download Code
Re: Saving Photos stored in LDAP
by Plankton (Priest) on Nov 02, 2011 at 21:26 UTC
Re: Saving Photos stored in LDAP
by sundialsvc4 (Abbot) on Nov 03, 2011 at 14:00 UTC

    Is it possible for you to obtain the JPG by other means so that you can do a binary comparison of “what it should be” versus “what you got?”   (For example, is there any web-page that you could go to which would show an employee’s winning smile, so that you could then save the image from right off that page using a right-mouse-click in a web browser?)   I think that, once you can manage to do this, the root cause of the problem will become obvious and this will save a lot of guesswork.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2014-10-31 04:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (214 votes), past polls