logo       
Google Custom Search
    AddThis Social Bookmark Button

Re: retrieve jpegPhoto: msg#00002

Subject: Re: retrieve jpegPhoto
I can assure you that it didn't worked without binmode(TMP) ! and now it works fine with it !
I run a   Red Hat Linux release 9 (Shrike) and perl v5.8.0.
??

jimharle@xxxxxxxxxxx wrote:

binmode is required on Windows clients.  Unix clients don't need it.
Great :-)
your code gave me a clue, I just add the magic binmode(OUT); and now it works fine, here's my new section of code:

$photo=$entry->get_attribute( 'jpegPhoto' );
    if(ref($photo))
      {
      $picture = @$photo[0];
      }
    else
     {
      print "\n";
      print "No jpegPhoto attribute for DN: $dn\n";
        }
open (TMP, ">./photos/$uid");
binmode(TMP);
$| = 1;
print TMP $picture;
close(TMP);

How comes the sample code from http://search.cpan.org/src/GBARR/perl-ldap-0.31/contrib/jpegDisplay.pl works without that ?? the $|=1 is only for streaming the flow (not buffered it) i suppose ? that not enough in my case !.
anyway it works for me now :-)

Brian K Johnson wrote:
The junk below is what I ended up having to do to stuff a jpg into
Windows 2003 Active Directory...and then to read it out. Maybe it will
give you some hints.



Code to read image data from Active Directory

use Net::LDAP;
$ldapnode="192.168.2.10";

$ldap = new Net::LDAP("$ldapnode",port => 389,debug =>3, version => 3)
or
        die "Failed on new\n";
$result=$ldap->ldapbind() || die "Bind Failed:$@"; @attr=("thumbnailPhoto"); $filter="(mail=bozo\@yyy.zzz.xxx)";
$mesg = $ldap->search(filter => $filter,attrs => [@attr], base =>
"CN=Users,DC=home,DC=yyy,DC=zzz,DC=xxx"
   ) or die "Search Failed using FILTER: $filter$@";

foreach $entry ($mesg->all_entries) {
$t=$entry->get("thumbnailPhoto");

}
open(OUT,">test.jpg");
binmode(OUT);
foreach(@$t){
        print OUT "$_";
}
close(OUT);
$ldap->unbind;



Code to put a photo in Active Directory

#get the name of the jpeg file
($in)=@ARGV;
open(IN,"$in");
binmode(IN);
$c=0;
while(<IN>){
        $c++;
        $photo=$photo.$_;
        print "NEXT: $c\n";
}
close(IN);
use Net::LDAP;
$ldapnode="192.168.2.10";

$ldap = new Net::LDAP("$ldapnode",port => 389,debug => 0) or
        die "Failed on new\n";


$pass="notmypassword";
$dn="bozo\@home.yyy.zzz.zzz";

$dnu="CN=bozo,CN=Users,DC=home,DC=yyy,DC=zzz,dc=xxx";

$ldap->ldapbind(dn => "$dn", password => "$pass") || die "Bind
Failed:$@";



if (!$photo){
        print "DELETE\n";
        $result=$ldap->modify( $dnu, delete => { thumbnailPhoto => [] }
);
        $err=$result->code;
}
else
{
        print "REPLACE\n";
        $result=$ldap->modify( $dnu, replace => { thumbnailPhoto =>
"$photo" } );
        $err=$result->code;
}

print "ERR: $err\n";


-----Original Message-----
From: Chris Ridd [mailto:chrisridd@xxxxxxx] Sent: Monday, March 29, 2004 10:04 PM
To: jehan.procaccia; perl-ldap@xxxxxxxx
Subject: Re: retrieve jpegPhoto

On 29/3/04 1:09 pm, jehan.procaccia <jehan.procaccia@xxxxxxxxxxx> wrote:


Hello,
I am trying to retrieve jpegPhotos from my openldap directory with Net::Ldap, however I keep getting files containing only "data" and not
a jpeg files.

I took inspiration from:
http://search.cpan.org/src/GBARR/perl-ldap-0.31/contrib/jpegDisplay.pl
here's the section of code I took:

$photo=$entry->get_attribute( 'jpegPhoto' );
That really ought to be:

    $photo=$entry->get_value( 'jpegPhoto' );

If you run the script with 'use warn;' you will see why.


if(ref($photo))
  {$picture = @$photo[0];}
else
 {print "\n";
print "No jpegPhoto attribute for DN: $dn\n";} open (TMP, ">./photos/$mail"); $| = 1; print TMP $picture; close(TMP);

$ file photos/Jehan.Procaccia\@int-evry.fr
photos/Jehan.Procaccia@xxxxxxxxxxx: data which cannot be viewed as a jpeg photo :-(

What I am doing wrong ?
Is there a difference between the value you retrieved and the value in
the file (ie is writing to the file going wrong)?

Are the JPEGs being *added* correctly to the server? Are any other
clients able to read the JPEGs?

Cheers,

Chris


Cheers,

Chris









Try Searching:
servers, voip, java, networking, microsoft ...
<Prev in Thread] Current Thread [Next in Thread>