I am using spring boot as backend and reactjs as frontend. I stored images and videos on server. then retrieve it to front end. when using localhost it works properly. but after i deployed this application on ubuntu server i can't preview images.(but image save process success). In ubuntu my spring boot jar file is located at /root/main/test. But uploaded images saved outside root folder(/upload/image.jpg). so i can't retrive this as full url. such as mydomain.com/upload/image.jpg isn't working. how can i get this image using react js
1 Answers
0
votes
You can configure spring boot to serve static content:
spring.resources.static-locations=file:/upload
or with code:
@Configuration
@EnableWebMvc
public class MvcConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/upload/**")
.addResourceLocations("file:/upload/");
}
...
{...., "thumbUrl": "http://ngnix-addr/url/image.jpg"}so react can render the image normally. And if you have spring-security, make sure that you allow access to those paths. - Aman