Hi Roger,
On Sep 26, 2011, at 14:24 , Roger KeIrad wrote:
Hi Lukas,
I ve got 2759 which is correct in the first and second call which is the right size of
the thumbnail.
The problem is that when I write the buffer to a file I only get 4 bytes (size of the
buffer).
The file is dumped in PHOTO field in incoming item.
Is there a mistake in the manner I use the extracted buffer? because I try to put the
buffer on a file by character.
That is binary data. If you have that processed by a character API, probability is high
that processing will stop at the first 0x00 / NUL character, because in text data this is
usually the terminating character, while in binary it is a part of the data like all other
values from 0x00..0xFF.
So I assume that the data you get into your buffer is fine, but has a 0x00 as the fifth
byte, which then stops the code you are using to write that to disk.
Plain fwrite should work, but not fputs for example, as this stops at the first 0x00
encountered.
Best Regards,
Lukas
2011/9/26 Lukas Zeller <luz(a)plan44.ch>
Hello Roger,
the code looks fine, exactly the way I am doing it to get the PHOTO data in my own plugin
I have for iOS address book.
So there's something else that must be wrong.
You say you get 2759 as size. Is this valsize in the first call?
And then in the second call you get only 4 bytes back? What does valsize return for the
second call? Also 4 or 2759?
Do you have a logfile where you see the incoming item dumped? If so, what does it show
for the PHOTO field?
Best Regards,
Lukas
On Sep 26, 2011, at 11:32 , Roger KeIrad wrote:
> Hi Lukas
> Thanks for the response. I followed your tips but It didn't work here is my code
:
>
> TSyError res = this->ui.GetValueByID(this,
> aItemKey,
> valueId,
> idx,
> sysync::VALTYPE_BUF,
> NULL,
> 0,
> &valsize
> );
> if(!res && valsize){
> data = SharedBuffer(new char[valsize*1024*1024 + 1],
valsize);
> data[valsize] = 0;
> res = this->ui.GetValueByID(this,
> aItemKey,
> valueId,
> idx,
>
sysync::VALTYPE_BUF,
> data.get(),
> valsize + 1,
> &valsize
> );
> }
>
> I ve got size = 2759 but i always extract 4 bytes.
> Can you help me please?
> Thank you in advance
> Regards
>
> 2011/9/22 Lukas Zeller <luz(a)plan44.ch>
> Hello Roger,
>
> On Sep 22, 2011, at 16:25 , Roger KeIrad wrote:
>
> > Hello,
> > It is me again.
> > I have some troubles with PHOTO for synchronised contact.
> > I used the same idea to extract encoded value to decode it.
> > I tried with GetValue and GetValueByID but no chance.
>
> Both should work (the PHOTO is not an array field).
>
> Just pass VALTYPE_BUF as type, and provide a buffer large enough to get the binary
photo data.
>
> To find out in advance how large the buffer needs to be, just call GetValue once
with a NULL pointer as buffer or zero buffer size. This will return the needed size in the
aValSize parameter, which you can use to allocate a buffer large enough to get the entire
PHOTO.
>
> If you pass a buffer that is too small for the entire PHOTO data, you'll get
LOCERR_TRUNCATED status.
>
> The data you get is binary data, usually a JPG. If you save the data 1:1 into a
file, any image viewer program should be able to show it.
>
> Best Regards,
>
> Lukas
Lukas Zeller, plan44.ch
luz(a)plan44.ch -
www.plan44.ch