REST API - Download attachment and upload it again

Benedikt Kaiser
Tera Contributor

Hi all, 

I am currently trying to download an attachment with the REST API and then upload the same attachment again.

However, I am experiencing some error when getting back the binary from the attachment. This results then in a corrupted file. For example the PDF-file is then an empty file when I try to upload it again. 

Only for a txt file it is working.

It looks like that the binary response from Service-Now has some errors in it?

"%PDF-1.7\r\n%����\r\n1 0 obj\r\n<</Type/Catalog/Pages 2 0 R/Lang(en-US) /StructTreeRoot 10 0 R/MarkInfo<</Marked true>>/Metadata 20 0 R/ViewerPreferences 21 0 R>>\r\nendobj\r\n2 0 obj\r\n<</Type/Pages/Count 1/Kids[ 3 0 R] >>\r\nendobj\r\n3 0 obj\r\n<</Type/Page/Parent 2 0 R/Resources<</Font<</F1 5 0 R>>/ExtGState<</GS7 7 0 R/GS8 8 0 R>>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI] >>/MediaBox[ 0 0 612 792] /Contents 4 0 R/Group<</Type/Group/S/Transparency/CS/DeviceRGB>>/Tabs/S/StructParents 0>>\r\nendobj\r\n4 0 obj\r\n<</Filter/FlateDecode/Length 223>>\r\nstream\r\nx���1k�0\u0010�w���\u001b���;ٱb\b\u0019b���\u0019B\u0004\u001dJ�\u0014���8i\u0012�߯\u001a��੾����}�\u000e���1���......."

Does anyone maybe had the same problems?

 

Thank you and best regards,

Benedikt Kaiser

5 REPLIES 5

Hi,

I don't think it is possible using OOB Attachment API

you can create your own scripted rest api and send base64encoded data as API response.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader