How to upload an image to sys_attachment table via Custom Service Portal Widget?

AyanshN
Tera Contributor

Hi everyone,

I'm working on a custom widget in Service Portal where I need to allow users to upload an image file (e.g., PNG or JPEG) and store it in the `sys_attachment` table, associated with a specific record (e.g., `sc_req_item`).

I'm not using the default file upload functionality (`nowAttachmentHandler`) due to customization needs, and would like to implement this purely through client-side code inside the widget.

### My questions:

1. What is the best practice to upload a file to the `sys_attachment` table from a custom widget?
2. Is there a standard REST endpoint or method I should use in the client controller to send the file?
3. Are there security considerations I should be aware of when uploading base64-encoded data?
4. How can I ensure the uploaded image is properly associated with a specific record (e.g., by `table_name` and `table_sys_id`)?

Any examples or guidance would be much appreciated. Thank you!

2 REPLIES 2

Mike Lynch
Tera Expert

The Attachment API Post method should cover what you need:
https://www.servicenow.com/docs/bundle/xanadu-api-reference/page/integrate/inbound-rest/concept/c_At...

 

Although  "due to customization needs" sounds like the real problem here. What are those needs that cannot be overcome by configuraiton or cloning an OOTB attachment widget and modifying?

Ankur Bawiskar
Tera Patron
Tera Patron

@AyanshN 

where are you planning to place it? share some screenshots

check these links on how it can be done

How to add an attachment functionality in a service portal widget form? 

Drag & Drop Attachments for Service Portal - FREE Widget 

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

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