image uploaded to SericeNow Task via JAVA rest API is shown as broken

bthulas
Mega Contributor

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  APIPNG Image broken when using JAVA REST API

1 ACCEPTED SOLUTION

Tony Chatfield1
Kilo Patron

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.

 

View solution in original post

2 REPLIES 2

Tony Chatfield1
Kilo Patron

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.

 

bthulas
Mega Contributor

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...