REST API - Download attachment and upload it again
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2022 03:04 AM
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
- Labels:
-
Change Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2022 03:12 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2022 03:24 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2022 09:46 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2022 12:08 AM
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