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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

it works fine with txt since it's simple text file

pdf, word, excel etc are complex files and you cannot directly upload it with the binary data you receive.

Can you explain what's your business requirement here?

Regards
Ankur

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

Benedikt Kaiser
Tera Contributor

Hi Ankur, 

thanks for your message. 

I need to download an attachment as a binary file from a SNOW customer-instance and want to upload the same attachment directly in our SNOW instance, because we need to copy the changes between the two instances.

Best regards,

Benedikt Kaiser

 

Hi,

then check these links since you want to copy files between 2 instances

Copying attachment from one instance to another 

Copying attachment from one instance to another+

Regards
Ankur

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

Hi Ankur, 

 

thank you for your help. I will try it this way. 

I have another question: Is it possible to download anattachment via the REST API in base64 format?

Best regards, 

Benedikt