Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring boot image display url

Hello i have images folder like this

enter image description here

What i want to do, is upload images to that folder and display them like this localhost:8080/image.jpg , so i can display it in frontend.. Nothing wrong is with upload, but i have no idea with displaying this images with api.

I already have tried

@Configuration
public class AdditionalResourceWebConfiguration implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(final ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/images/**").addResourceLocations("file:images/");
    }
}

But this is not working..

like image 654
angnewb Avatar asked Dec 01 '25 10:12

angnewb


1 Answers

What i want to do, is upload images to that folder and display them like this localhost:8080/image.jpg

URL should be localhost:8080/images/image.jpg as you are saving the images in images folder and mapping them as /images in addResourceHandler method

@Configuration
public class AdditionalResourceWebConfiguration implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(final ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/images/**")
                  .addResourceLocations("file:images\\");
    }
}
like image 71
Fahim Feroje Al Jami Avatar answered Dec 03 '25 23:12

Fahim Feroje Al Jami



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!