Convert binary attachment file to base64 and attach in the attachment table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 04:13 AM
Hi All,
I am encountering an issue where the response is coming in Binary format (as shown in the attached file) but when we are trying to convert it into base64 and attaching in the sys_attachment table, it is getting attached as a corrupt file. I am using below code in the action of flow designer.
Binary Response screenshot
var respBody = inputs.responseBody;
//var contentType = headerVal.content-type;
//var contentType = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
var contentType = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
var attachmentContent = attachment.getContentBase64(respBody);
var StringUtil = new GlideStringUtil();
var base64EncodedData = StringUtil.base64Encode(respBody.toByteArray());//.toByteArray()
//var content = attachmentContent;
gs.log(attachmentData,'vaibhavheader');
var eccGr = new GlideRecord('ecc_queue');
eccGr.initialize();
eccGr.setValue('agent', 'AttachmentCreator');
eccGr.setValue('topic', 'AttachmentCreator');
eccGr.setValue('name', 'testdocument.docx' + ':' + contentType); // give here the file name and content type
eccGr.setValue('source', 'incident' + ':' + '3de8e6ee83560a108d1133326daad3ad'); // give here the table name and record sysId to which you need to attach
eccGr.setValue('payload',attachmentData );
eccGr.insert();
})(inputs, outputs);
Ask is to convert the response body in the base64 format and attach the file in the attachment table. I have attached the file "testdocument.docx" and response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 04:38 AM
Refer to the below link.
Thanks
dgarad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 06:33 AM
Thanks. I have already tried the given code but it is not working.