Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

How to fetch fileupload image from frontend in java

Avatar

Level 3

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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 

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

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