source: src/main/java/it/finki/charitable/config/MvcConfig.java@ 5577566

Last change on this file since 5577566 was 5577566, checked in by NikolaCenevski <cenevskinikola@…>, 3 years ago

prototip part 2

  • Property mode set to 100644
File size: 991 bytes
Line 
1package it.finki.charitable.config;
2
3import org.springframework.context.annotation.Configuration;
4import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
5import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
6
7import java.nio.file.Path;
8import java.nio.file.Paths;
9
10@Configuration
11public class MvcConfig implements WebMvcConfigurer {
12
13 @Override
14 public void addResourceHandlers(ResourceHandlerRegistry registry) {
15 exposeDirectory("post-photos", registry);
16 exposeDirectory("moderator-photos", registry);
17 }
18
19 private void exposeDirectory(String dirName, ResourceHandlerRegistry registry) {
20 Path uploadDir = Paths.get(dirName);
21 String uploadPath = uploadDir.toFile().getAbsolutePath();
22 if(dirName.startsWith("../")) {
23 dirName = dirName.replace("../", "");
24 }
25 registry.addResourceHandler("/" + dirName + "/**").addResourceLocations("file:/"+ uploadPath + "/");
26 }
27}
Note: See TracBrowser for help on using the repository browser.