Any get GlideSysAttachment.write to work for binary files while in a scope?

reedwowens
Giga Expert

I have been bashing my head against this and can't believe I'm the only one to run into this.   Hope it's just I'm doing something wrong.

To test problem I created a simple form with an encoded data field and a UI action:

var sa = new GlideSysAttachment();

var binData = gs.base64Decode(current.encoded_contents);

sa.write(current, "Test.pdf", "application/pdf",binData);

action.setRedirectURL(current);

You would think this works... NOPE.   I get an attachment.   It thinks it's PDF and it's about 20% larger than the original.   All the ascii text is correct in it but the binary is messed up.

I've tested the encode/decode -> mid server (did it in java) -> server... All working but this write function.

Developer site has only the description of the call and it's function.   No examples.   From my "working with it' it does take the text and write it to the attachment..

Any help/insight would be greatly appreciated!

Just tried another obvious thing.   Added a PDF as an attachment to this record and ran the following UI Action:

var gr = new GlideRecord("sys_attachment");

gr.addQuery( "table_name", "=", "x_uxs_test_error_table");

gr.addQuery( "table_sys_id", "=" , current.sys_id + "");

gr.query();

if (gr.next()) {

  gs.addInfoMessage("Getting attachment");

  var sa = new GlideSysAttachment();

  var contents= sa.getContentBase64(gr);

  gs.addInfoMessage("Got Contents: ");

  current.encoded_contents = contents;

  current.update();

  sa.write(current, "newOrig.pdf","application/pdf", gs.base64Decode(contents));

}

action.setRedirectURL(current);

I get the infomessages.   I get the data in base64 encoded on the form.   I get a second "newOrig.pdf" and it's wrong!

1 ACCEPTED SOLUTION

reedwowens
Giga Expert

I've got this in as a bug to ServiceNow.   They are aware of the issue and looking at fixing it in a future release.   For now GlideSysAttachment().write() works only for text files and is not binary safe.   Problem


View solution in original post

19 REPLIES 19

reedwowens
Giga Expert

I've got this in as a bug to ServiceNow.   They are aware of the issue and looking at fixing it in a future release.   For now GlideSysAttachment().write() works only for text files and is not binary safe.   Problem


Hi, Reed.   Has there been any update on this from ServiceNow?   I just ran into the same issue, and to say the least, it makes things difficult if you need to deal with binary attachments in scoped apps.



Thanks...



-- Bill


Call me on my cell


Hi Reed,



      Thank you for your post! I am running into the same issue although we are not in a scope app(not sure if it makes a difference). I am able to attach to the record what appears to be a pdf but when   I try to open it it can't recognize the file. Did you find any work around this? The version I work in is Fuji. I will greatly appreciate your time,




--Stef