[Vobject] Unable to add photo to vcard (Address Book OS X 10.6.4)

Matthew Leingang leingang at courant.nyu.edu
Sat Sep 18 05:10:59 CDT 2010


No worries.  The exact same thing happened to me and now that I have it fixed I protect that snippet like it was gold.

Best,
Matthew Leingang

On Sep 17, 2010, at 4:34 AM, Roberto Aguilar wrote:

> Jeffrey & Matthew,
> 
> Thanks for the response.  I swear I tried a very similar snippet as the one below prior to emailing, but whatever was broken is now fixed with your magic snippet.
> 
> Thanks!
> -Roberto.
> 
> On Sep 16, 2010, at 7:46 AM, Jeffrey Harris wrote:
> 
>> Hi Roberto,
>> 
>> I suspect Matthew's answer should solve your problem, unless Address Book has gotten even more finicky about reading photos (which is possible, but would be odd).
>> 
>> The key is that vobject's serialize handles encoding for you, if you give it an encoding parameter that it recognizes (in vcard 3.0's case, the base64 encoding parameter is "B").
>> 
>> Setting the global flag vcard.wacky_apple_photo_serialize to False (it defaults to True) would try to serialize vcard photo details "correctly", i.e., by folding the base64 encoded lines at 80 characters or so. This isn't done, normally, because historically AddressBook expected very specific extra whitespace if lines were folded.
>> 
>> Let me know if that doesn't solve the issue for you!
>> 
>> - Jeffrey
>> 
>>> I don't remember why, but this is a tricky one to get working.  Here's what I do and it's worked for me:
>>> 
>>>          photo_fh=open(photo_filename,'rb')
>>>          card.add('photo') 
>>>          card.photo.value = photo_fh.read()
>>>          card.photo.encoding_param = "b" 
>>>          card.photo.type_param = "JPEG" 
>> 
>> _______________________________________________
>> VObject mailing list
>> VObject at lists.skyhouseconsulting.com
>> http://lists.skyhouseconsulting.com/mailman/listinfo/vobject
> 
> _______________________________________________
> VObject mailing list
> VObject at lists.skyhouseconsulting.com
> http://lists.skyhouseconsulting.com/mailman/listinfo/vobject
> 

-- 
Matthew Leingang                             |  leingang at courant.nyu.edu
Clinical Associate Professor of Mathematics  |  Vice Chair for Undergraduate Affairs
Courant Institute of Mathematical Sciences   |  Department of Mathematics



More information about the VObject mailing list