Setting encoding type in Photo field

44 views
Skip to first unread message

Sachin Gupta

unread,
Mar 5, 2014, 9:46:27 AM3/5/14
to ez-vcard...@googlegroups.com
Hi Mike,

I am trying to generate a Photo field in the vcard with encoding as Base64 or bin.
Sample: PHOTO;TYPE=JPEG;ENCODING=BASE64:

Can you please guide me on how to achieve this?
I was able to set the type=jpeg, but could not set the encoding=base64.

Also the photo field gets dumped with VALUE=url:

Can i suppress this anyhow?

Regards
Sachin

Sachin Gupta

unread,
Mar 5, 2014, 9:59:29 AM3/5/14
to ez-vcard...@googlegroups.com
Infact i am not even getting the field JPEG as type=jpeg.
It simply dumps as PHOTO;JPEG;VALUE=url:

Instead required as PHOTO;ENCODING=BASE64;TYPE=JPEG:MIICajCCAdOgAwIBAgI…

Regards
Sachin

Michael Angstadt

unread,
Mar 5, 2014, 12:45:21 PM3/5/14
to ez-vcard...@googlegroups.com
Can you post your code?

-Mike


--
You received this message because you are subscribed to the Google Groups "ez-vcard-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ez-vcard-discu...@googlegroups.com.
To post to this group, send email to ez-vcard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ez-vcard-discuss/e16af778-f51c-41f8-88be-d9c7e92f06f0%40googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Sachin Gupta

unread,
Mar 5, 2014, 11:48:16 PM3/5/14
to ez-vcard...@googlegroups.com
Hi Mike,

PFB the code.

byte buffer[]=FileUtils.readFileToByteArray(f);
String ascii=Base64.encodeBase64String(buffer);
photo = new Photo(ascii, ImageType.JPEG);

Using apache commons apis to encode the image in base 64 and then setting it into Photo.

With this getting the vcard entry as:
PHOTO;JPEG;VALUE=url:/9j/4A...

Regards
Sachin




Michael Angstadt

unread,
Mar 6, 2014, 12:47:08 PM3/6/14
to ez-vcard...@googlegroups.com
Sachin,

You do not need to convert the photo's binary data into a base64 string.  ez-vcard does this automatically when the vCard is written.  Simply pass the raw byte array into the Photo constructor.

byte buffer[]=FileUtils.readFileToByteArray(f);
photo = new Photo(buffer, ImageType.JPEG);

Regards,
-Mike


Sachin Gupta

unread,
Mar 6, 2014, 2:04:56 PM3/6/14
to ez-vcard...@googlegroups.com

Thanks mike.

But how do i get the desired format of the field as mentioned in my prev mail. Including the encoding part also.

Rgds
Sachin

Sachin Gupta

unread,
Mar 6, 2014, 2:08:26 PM3/6/14
to ez-vcard...@googlegroups.com

I mean, like this

PHOTO;TYPE=JPEG:ENCODING=BASE64

Regards

Sachin Gupta

unread,
Mar 6, 2014, 2:16:59 PM3/6/14
to ez-vcard...@googlegroups.com

And what do i need to do to set the photo field in bin mode instead the base64 encoding? There seems to be an encoding property, but that seems to be for the whole vcard.

Regards

Michael Angstadt

unread,
Mar 6, 2014, 3:38:38 PM3/6/14
to ez-vcard...@googlegroups.com
The value of the ENCODING parameter varies depending on the vCard version.  Version 2.1 uses "base64", while version 3.0 uses "b".


Reply all
Reply to author
Forward
0 new messages