lukassz
lukassz

Reputation: 3340

Spring webserver how to share file in folder

How can I share file in folder using Spring eg. /tmp/file.mp4. that it is accessible from the IP? Like this 10.11.14.122/file.mp4

Upvotes: 0

Views: 1184

Answers (1)

chengpohi
chengpohi

Reputation: 14217

Your question is need spring-boot to serve your static files. You just need to configure the path in Override addResourceHandlers, full code:

@SpringBootApplication
public class TmpApplication extends WebMvcConfigurerAdapter {

    public static void main(String[] args) {
        SpringApplication.run(TmpApplication.class, args);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/tmp/**").addResourceLocations("file:///./myfolder/")
                .setCachePeriod(0);
    }
}

There is a document: boot-features-spring-mvc-static-content

Upvotes: 3

Related Questions