Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Rest API call with File upload

Avatar

Level 4

Dear Team,

 

We have come across below requirement:

 

1) We have HTML form with few input fields along with File upload option.

2) Once we submit form, It should call POST rest API and pass on all parameters along with file in some way and based on API response, we need to display messages.

 

Do we have any reference or example for this one?

 

Regards,

Arvind

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @arvind 

Please find below steps to pass file input.

 

Javascript

Pass this file input in rest API ajax request as request parameter.

fileInput : $('#file-input')[0].files[0]

 

Backend Servlet :

RequestParameter uploadedFile = request.getRequestParameter("fileInput");
InputStream inputStream = uploadedFile.getInputStream();

 

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

Hi @arvind 

Please find below steps to pass file input.

 

Javascript

Pass this file input in rest API ajax request as request parameter.

fileInput : $('#file-input')[0].files[0]

 

Backend Servlet :

RequestParameter uploadedFile = request.getRequestParameter("fileInput");
InputStream inputStream = uploadedFile.getInputStream();