- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2017 11:49 AM
var decodedContent = GlideStringUtil.base64Decode(content);
var gsa = new GlideSysAttachment();
var attachmentSysID = gsa.write(grTarget, fileName, contentType, decodedContent);
Where -
- "content" is base64 encoded text for the attachment file.
- "grTarget" is the object of the target record.
- "filename" is the attachment file name.
- "contentType" is the type of the attachment file to be created.
The above code is working properly when the contentType is "txt" but for other types of files (images/pdf etc.) it's not working properly - it's creating corrupted image/pdf. Any idea - what's the issue here?
I tried using writeBase64() function instead of just write() - but no help!
P.S: I tried to paste the raw base 64 encoded text into https://www.base64decode.org/ and decoded it from there manually - it created the image/pdf files in expected format.
Message was edited by: Hitesh Patel
Solved! Go to Solution.
- Labels:
-
Knowledge Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2017 12:12 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2017 12:12 PM
Please use 'base64DecodeAsBytes'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2017 02:30 PM
Thanks Amlesh for the answer. Using the function base64DecodeAsBytes() instead of base64Decode() resolved my issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2018 12:15 AM
But GlideStringUtil is not allowed in scoped applications. Then what would be the solution for Scopped apps?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2019 03:39 PM
you can create a global script include with the attachment parse code and call it from your scope.