How to Send Images in Spring Boot without using Servlet and Redundant JSP Codes? Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report Open IntelliJ IDE and in the Controller section of your project inside the Controller class you need to build the Image serve method. The Image serve method looks like below and as you have to collect the Image response use @GetMapping Annotation to collect the image. ImageHandler Controller Method Create a directory to upload images from the system to your respective IDE; here in our case, It is IntelliJ. Creating Directory In IDE to upload Image Here, we created a directory as Mica Check and uploaded the file below: Directory along with uploaded File Now time to get the Image from FileInput Stream and put it under the try-catch block as below Adding an Image from InputStream and giving the path of the file You getting an Image response and for that, you need to reflect the content type of the Image by adding HTTPSERVLET RESPONSE in the controller method parameter and the content type should be MEDIATYPE.(FILE_FORMAT) Java @GetMapping("/serve-image") public void serveImageHandler(HttpServletResponse response) { try { InputStream fileInputStream= new FileInputStream("MicaCheck/Resignation__Approval.png"); response.setContentType(MediaType.IMAGE_JPEG_VALUE); StreamUtils.copy(fileInputStream,response.getOutputStream()); } catch(Exception e) { e.printStackTrace(); } } StreamUtils.copy(file input stream,response.getOutputStream()); The above lines copy the file input stream to the response.getOutputStream. Now your Image Serve Controller method is ready. Now test it on the postman client by hitting URI as in the below Image. Comment More infoAdvertise with us Next Article How to Send Images in Spring Boot without using Servlet and Redundant JSP Codes? R rohan srivastava 2 Follow Improve Article Tags : Java Java-Spring-Boot Practice Tags : Java Similar Reads Difference between Spring MVC and Spring Boot 1. Spring MVC : Spring is widely used for creating scalable applications. For web applications Spring provides Spring MVC framework which is a widely used module of spring which is used to create scalable web applications. Spring MVC framework enables the separation of modules namely Model View, Con 3 min read Spring Boot - Spring JDBC vs Spring Data JDBC Understanding the difference between Spring JDBC and Spring Data JDBC is important for choosing the right approach to interact with relational databases in Spring Boot applications. Both frameworks serve the same purpose but differ significantly in terms of abstraction, ease of use, and developer pr 5 min read Best Practices For Structuring Spring Boot Application Spring Boot is built on top of the conventional spring framework. So, it provides all the features of spring and is yet easier to use than spring. In this article, we are going to see how one should start and structure his Spring Boot application. Prerequisites: Good knowledge of Java.Basic knowledg 3 min read Spring Boot - Start/Stop a Kafka Listener Dynamically In a Spring Boot application, Kafka Listeners start automatically once the application launches and they listen for messages from Kafka topics. But there are many scenarios where we might need to dynamically start or stop a Kafka listener based on certain conditions. This can be achieved using Kafka 6 min read How To Dockerize A Spring Boot Application With Maven ? Docker is an open-source containerization tool that is used for building, running, and managing applications in an isolated environment. It facilitates the developers to bundles its software, libraries, and configuration files. The Docker facilitates with isolating the one container from another. In 12 min read Dynamic Dropdown From Database using Spring Boot The concept of dynamic dropdown (or dependent dropdown) is exciting and challenging to code. Dynamic dropdown means that the values in one dropdown list are dependent on the value selected in the previous dropdown list. A simple example would be three dropdown boxes displaying names of the district, 11 min read Spring - RestTemplate Due to high traffic and quick access to services, REST APIs are getting more popular and have become the backbone of modern web development. It provides quick access to services and also provides fast data exchange between applications. REST is not a protocol or a standard, rather, it is a set of ar 7 min read Spring Boot - Scheduling Spring Boot provides the ability to schedule tasks for execution at a given time period with the help of @Scheduled annotation. This article provides a step by step guideline on how we can schedule tasks to run in a spring boot application Implementation:It is depicted below stepwise as follows:Â St 4 min read Spring Boot - Sending Email via SMTP Spring Boot provides the ability to send emails via SMTP using the JavaMail Library. Here we will be illustrating step-by-step guidelines to develop Restful web services that can be used to send emails with or without attachments. In order to begin with the steps, let us first create a Spring Boot p 5 min read Different Ways to Establish Communication Between Spring Microservices If you are working with a Spring Boot project which involves multiple microservices, You might have felt the need to communicate from microservice m1 to microservice m2. Depending upon business use-cases, this communication can be of synchronous or asynchronous type. Before digging dip further. Let' 3 min read Like