Last change
on this file since 0f4f552 was 5577566, checked in by NikolaCenevski <cenevskinikola@…>, 3 years ago |
prototip part 2
|
-
Property mode
set to
100644
|
File size:
991 bytes
|
Line | |
---|
1 | package it.finki.charitable.config;
|
---|
2 |
|
---|
3 | import org.springframework.context.annotation.Configuration;
|
---|
4 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
---|
5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
---|
6 |
|
---|
7 | import java.nio.file.Path;
|
---|
8 | import java.nio.file.Paths;
|
---|
9 |
|
---|
10 | @Configuration
|
---|
11 | public 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.