developerforce / Force.com-JavaScript-REST-Toolkit

ForceTK - a minimal Force.com REST API for JavaScript apps
BSD 3-Clause "New" or "Revised" License
315 stars 175 forks source link

Retrive method can not transfer attchment base64 string body correctly #81

Closed MessShawn closed 8 years ago

MessShawn commented 8 years ago

I've got an issue to download attachment body in our app. We use forcetk retrieve method and never got the body data but the uri(something like '/services/data/v33.0/sobjects/Attachment/00P25000000aiNREAY/Body'). Then I use the ajax method of forcetk client directly to call the resource 'services/data/v33.0/sobjects/Attachment/00P25000000aiNREAY/Body' and every time it results to error handling function. it seems that the responseText is right but when I use btoa(unescape(encodeURIComponent(XXX))) to convert the result into base64 string, the converted data is never matches correct . Would you give me some advice here?

metadaddy commented 8 years ago

Can you post the code, and the errors you're seeing in the JavaScript Console?

MessShawn commented 8 years ago

here is the code: 2015-11-13 12 03 42 and logs:

2015-11-13 12 04 25

it's a cordova app running on ios device

The error seems to be throwned by jQuery response convertor. What confused me is that is there a standard method that the forcetk offered to fetch attachment body as the retrieve method can not get the data?

metadaddy commented 8 years ago

The problem is that the query returns binary data, rather than text (see the docs). You should be able to use getChatterFile instead of ajax.

MessShawn commented 8 years ago

@metadaddy-sfdc I've solved the problem, thanks a lot~

ghost commented 8 years ago

What did you need to change?

On Thursday, November 12, 2015, Simon Xiao notifications@github.com wrote:

@metadaddy-sfdc https://github.com/metadaddy-sfdc I've solved the problem, thanks a lot~

— Reply to this email directly or view it on GitHub https://github.com/developerforce/Force.com-JavaScript-REST-Toolkit/issues/81#issuecomment-156336321 .

Cheers,

Pat

MessShawn commented 8 years ago

@metadaddy-sfdc use the getChatterFile method to download attachment body and convert the response data as array buffer directly.

metadaddy commented 8 years ago

Great! Closing the issue, since it seems like you're all set.