developerforce / Force.com-JavaScript-REST-Toolkit

ForceTK - a minimal Force.com REST API for JavaScript apps

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Retrive method can not transfer attchment base64 string body correctly

MessShawn opened this issue · comments

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?

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

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?

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.

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

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
#81 (comment)
.

Cheers,

Pat

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

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