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. Create Quiz Comment R rohan srivastava 2 Follow 0 Improve R rohan srivastava 2 Follow 0 Improve Article Tags : Java Java-Spring-Boot Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References7 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers1 min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like