GlideSysAttachment write of GlideSysAttachment getContent have different result
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-02-2016 07:34 AM
I am using restMessage to fetch image and attach it to records image type field in scoped app.
At start i just used rest saveResponseBodyAsAttachment method but that doesn't let me insert the attachment with just 'image' as it's name in case that instance has whitelist of allowed extensions filled and not blank.
So i wanted to save the attachment as 'image.jpeg' and then use
GlideSysAttachment.write(current, 'image', 'image/jpeg', GlideSysAttachment.getContent(gr)); // where gr is the original attachment
unfortunately these 2 attachments ends up to be completely different attachment.getContent gives me result as if I try to GlideSysAttachment.write restResponse.getBody() as the content.
I ran out of options how to do this beside of clearing the whitelist of extensions or allowing my scoped app write access to sys_attachment table and just using update and neither of these solutions are going to work for me.
Thanks for help.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-02-2016 07:48 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-02-2016 08:19 AM
Thanks for this but i am afraid this won't help me because i don't have the base64encoded data of the image and I can't find out how to get it.
This is what i get if I open the image I get from restResponse.getBody() as text vs the valid picture i get from restResponse.saveResponseBodyAsAttachment()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2017 01:32 AM
Did you find a solution for getting the content?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2017 02:02 AM
Hi,
I did not find a solution for getting the content but I did find solution (thought not ideal) for the attachment handling.
var rest= new sn_ws.RESTMessageV2('<table>.Image', 'get');
rest.setEndpoint(current.image_link.toString());
rest.saveResponseBodyAsAttachment('<table>', current.sys_id, 'image.jpeg', 'image/jpeg');
var imageResponse = rest.execute();
var gr = new GlideRecord('sys_attachment');
gr.get(imageResponse.getResponseAttachmentSysid());
// This part works only if sys_attachment table has cross scope write access allowed for <scoped app>
gr.file_name = 'image';
gr.table_name = 'ZZ_YY<table>';
gr.update();
Hope this helps