- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2023 12:08 PM - edited ‎01-12-2023 12:09 PM
Hello All,
I am trying to upload an PNG image to ServiceNow Task using JAVA rest API.
I was able to upload the image but its shown as broken<image attached>.
When using attachment API via POSTMEN or REST API Explorer its working fine, the image is appearing correctly.
I tried all the methods (Binaryfile, file, byte array resource) in JAVA Rest using File Attachement API.
When using file Upload API, i am getting below error
{"message":"Failed to create the attachment. File part might be missing in the request.","detail":null},"status":"failure"}]
So far only "File Attachment API" api works for but the image get attached as broken image.
Any help or suggestion on this ? Thank you.
TIAPNG Image broken when using JAVA REST API
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2023 12:28 PM
Hi, have you compared records for the same file uploaded manually or via REST in sys_attachment table?
checked the file size, that the content_type is correct etc.
If the file uploads successfully via REST\Attachment API, but not via your Java code, then the issue is probably your java code\configuration and as the forum does not have visibility of this there is not a lot of help we can provide.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2023 12:28 PM
Hi, have you compared records for the same file uploaded manually or via REST in sys_attachment table?
checked the file size, that the content_type is correct etc.
If the file uploads successfully via REST\Attachment API, but not via your Java code, then the issue is probably your java code\configuration and as the forum does not have visibility of this there is not a lot of help we can provide.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2023 02:32 PM
you are right. I found this article helpful as well.
It seems I was not sending the payload as Binary data before. After I changed the payload as Binary, it got attached properly as a PNG image. Thank you for the suggestion
https://stackoverflow.com/questions/56184470/how-to-frame-resttemplate-for-request-body-of-type-bina...