You need to sign in to do that
Don't have an account?
venkateshp
Sending images from salesforce using apex rest api to mobile clinets
IN one project, we are provinding webservices from salesforce APEX REST API, we are sending data from salesforce to Mobile clients successfully, i need to send the images also , which are stored in the notes and attachments related to the record. But rest response not allowed to sendme the blob content(Attachment body). Is there any work around to send images from salesforce through apexRest to mobile clinets.
Its pretty urgent to me
Thanks in advance!
Warm Regards
Venkatesh
Your response can be a blob, its just that the autoamatic serialization doesn't work for blobs, but you can still write the blob to the responseBody, e.g.
This returns the blob as the response, e.g. using curl you can fetch the blob and store it with
Hi Simon,
Thank you so much for quick response
i am trying to customize the json response while sending to cleint like below
@RestResource(urlMapping='/Account/*')
global with sharing class account{
@HttpGet
global static List<accountParser> doGet(){
RestRequest req = RestContext.request;
String id=ree.params.get('id');
RestResponse res = RestContext.response;
res.addHeader('Content-Type','image/jpg');
list<Accountparser> accParser=new List<Accountparser>();
Account acc=[select name,id from account where name];
Attachment att=[select id ,body from Attachment where parentId=acc.id];
Accountparser ac= new Accountparser(acc.id,acc.name,att.body);
accParser.add(ac);
return acc;
}
}
global class Accountparser{
String id;
string name;
blob body;
global AccountParser(String id, String name,Blob body){
this.id=id;
this.name=name;
this.body=body;
}
but getting error like
Error: Compile Error: Invalid type for Http* method: LIST.LoginPraser.Blob
without blob content the code working fine. Please help me
Thank you in advance
Venkatesh
You can not return json data & binary data at the same time, it would need to be 2 separate resources. (or you need to base64 encode the binary data and retun that as a string within your json, not recommended)
Hi Simon,
1.can i call two resources at a single call request
2. If i do base64 encode to the binary data as a string using EncodeUtils.encodeBase64(blobdata.'UTF-8')
how the client app will retrive image from thsi string , what decription techniques need to client app follow.
Warm Regards,
Venkatesh