Search code examples
iphoneiosobjective-csalesforcent-native-api

how to access Salesforce Attachment Body (base64 binary data) in ios?


I am working on iOS native app for getting attachments from salesforce.

I have to show the salesforce attachments in my iPhone app for particular object like Leads,Contacts etc. For that i am using Rest Api and got response body. But in response body there is url but i want binary data of attachment body.

Here is my code:

My rest api request

NSString *attachments=[NSString stringWithFormat:@"select Name,Body, ContentType from   Attachment"];
SFRestRequest *request = [[SFRestAPI sharedInstance] requestForQuery:attachments];
[[SFRestAPI sharedInstance] send:request delegate:self];

I get response in body in following format:

{
    Body = "/services/data/v23.0/sobjects/Attachment/00P90000004SRFlEAO/Body";
    ContentType = "application/video";
    Name = "Video.MOV";
    attributes =     {
       type = Attachment;
        url = "/services/data/v23.0/sobjects/Attachment/00P90000004SRFlEAO";
    };
}

Solution

  • You have to make a GET request to the URL returned in the Body field to fetch the actual binary content.