How to fetch fileupload image from frontend in java | Community
Skip to main content
New Participant
April 28, 2023
Solved

How to fetch fileupload image from frontend in java

  • April 28, 2023
  • 1 reply
  • 854 views

Hi , I have a form where end user will upload a image from his system from <input type="file"> and I need to fetch this image in my post servlet java file and write in excel sheet in dam path.

 

Any piece of code or suggestions will help.

 

Thanks

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Sady_Rifat

Hello @ashar02 ,

For this, you need to use Multipart/form-data. POST form data into the servlet and you can receive the image from the body part.

Once you got the image convert it into inputStream and put it into the excel cell.

JS request: https://stackoverflow.com/questions/5392344/sending-multipart-formdata-with-jquery-ajax 

The Java servlet code will be like this

RequestParameterMap requestParameterMap = request.getRequestParameterMap(); RequestParameter image = requestParameterMap.getValue("image"); InputStream inputStream = image.getInputStream();

 

Follow this article to put the image in excel: https://www.baeldung.com/java-add-image-excel 

1 reply

Sady_Rifat
Sady_RifatAccepted solution
New Participant
April 28, 2023

Hello @ashar02 ,

For this, you need to use Multipart/form-data. POST form data into the servlet and you can receive the image from the body part.

Once you got the image convert it into inputStream and put it into the excel cell.

JS request: https://stackoverflow.com/questions/5392344/sending-multipart-formdata-with-jquery-ajax 

The Java servlet code will be like this

RequestParameterMap requestParameterMap = request.getRequestParameterMap(); RequestParameter image = requestParameterMap.getValue("image"); InputStream inputStream = image.getInputStream();

 

Follow this article to put the image in excel: https://www.baeldung.com/java-add-image-excel