You need to sign in to do that
Don't have an account?
Rakesh E
How to Store Binary data into salesforce attachment
Hi,
i wrote a Custom Web Service in Salesforce to acceprt Base64 encoded files (PDF/Text) and store them as Attachments.
it worked fine. But the other integration partner has changed the format to "Binary" and my code is not working now.
so is there any way to store the files which are received in binary format in an attachment.
i heard that we can store binary format also, but unable to find out the exact process.
please let me know if anyone has idea about this.
thanks in advance
Regards,
Rakesh
To store the image, use an <apex:inputFile> element; the uploaded file will be assigned to a value in your controller as a BLOB (Binary Large OBject). From there, you can store it as a Document, Attachment, or Content.
To view the image on the screen, just provide a link to the content (e.g. "/servlet/servlet.FileDownload?file={!file.id}").
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000915KIAQ
Also, see the link below,
http://blogs.developerforce.com/developer-relations/2011/09/using-binary-data-with-rest.html
Regards,
Ashish
Blob b ='Your binary value result';
attachments.body =b;
insert attachments;
try this if it works.
Try the following ways :
1 .HttpResponse res = new HttpResponse();
Blob beforeBlob = res.getBodyAsBlob();
Attachment objAttachmnt = new Attachment(parentId ='URParentID', name= 'Shipment.pdf', body = beforeBlob);
insert objAttachmnt;
2. Attachment objAttachmnt = new Attachment(parentId = sObjectToBind.Id, name= 'Contract.pdf', body = EncodingUtil.base64Decode(YOURBODY));
insert objAttachmnt;
Thanks ,
Ajay