diff --git a/src/main/java/com/onekeycall/videotablet/config/FilePath.java b/src/main/java/com/onekeycall/videotablet/config/FilePath.java index df4393a..696b554 100644 --- a/src/main/java/com/onekeycall/videotablet/config/FilePath.java +++ b/src/main/java/com/onekeycall/videotablet/config/FilePath.java @@ -1,7 +1,13 @@ package com.onekeycall.videotablet.config; +import java.io.File; + public class FilePath { + public static final String UPLOAD_FILE_PATH = "uploadFile"; public static final String TABLET_PATH = "tablet"; public static final String AVATAR_PATH = "avatar"; + public static String getAvatarPath(){ + return UPLOAD_FILE_PATH + File.separator + TABLET_PATH + File.separator + AVATAR_PATH + File.separator; + } } diff --git a/src/main/java/com/onekeycall/videotablet/config/FileService.java b/src/main/java/com/onekeycall/videotablet/config/FileService.java deleted file mode 100644 index 7ebd077..0000000 --- a/src/main/java/com/onekeycall/videotablet/config/FileService.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.onekeycall.videotablet.config; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -@Component -public class FileService { - @Value("${file.upload.path}") - private String uploadPath; - - // 使用uploadPath操作外部文件 - public void processFile(String fileName) { - String fullPath = uploadPath + fileName; - // 文件操作逻辑... - } -} \ No newline at end of file diff --git a/src/main/java/com/onekeycall/videotablet/config/SecurityConfig.java b/src/main/java/com/onekeycall/videotablet/config/SecurityConfig.java index 736f411..a3ee6eb 100644 --- a/src/main/java/com/onekeycall/videotablet/config/SecurityConfig.java +++ b/src/main/java/com/onekeycall/videotablet/config/SecurityConfig.java @@ -27,6 +27,7 @@ public class SecurityConfig { .authorizeHttpRequests(auth -> auth .requestMatchers("/ws/**").permitAll() .requestMatchers("/api/ws/**", "/topic/**").permitAll() + .requestMatchers("/uploadFile/**").permitAll() .requestMatchers("/public/**").permitAll() .requestMatchers("/sn/**").permitAll() .requestMatchers("/user/**").permitAll() diff --git a/src/main/java/com/onekeycall/videotablet/config/WebConfig.java b/src/main/java/com/onekeycall/videotablet/config/WebConfig.java index de2e5eb..5915077 100644 --- a/src/main/java/com/onekeycall/videotablet/config/WebConfig.java +++ b/src/main/java/com/onekeycall/videotablet/config/WebConfig.java @@ -19,4 +19,9 @@ public class WebConfig implements WebMvcConfigurer { // .addPathPatterns("/user/**") // 保护用户相关端点 // .excludePathPatterns("/public/**"); // 开放登录注册 // } + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("/uploadFile/**").addResourceLocations("file:uploadFile/"); + } } diff --git a/src/main/java/com/onekeycall/videotablet/controller/ManageSnController.java b/src/main/java/com/onekeycall/videotablet/controller/ManageSnController.java index ac26963..d942c71 100644 --- a/src/main/java/com/onekeycall/videotablet/controller/ManageSnController.java +++ b/src/main/java/com/onekeycall/videotablet/controller/ManageSnController.java @@ -11,11 +11,9 @@ import com.onekeycall.videotablet.service.UserService; import com.onekeycall.videotablet.utils.CXAESUtil; import com.onekeycall.videotablet.utils.JwtUtil; import com.onekeycall.videotablet.utils.TextUtils; -import org.apache.tomcat.util.http.fileupload.FileUploadException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -30,9 +28,6 @@ import java.util.Map; public class ManageSnController { Logger logger = LoggerFactory.getLogger(ManageSnController.class); - @Value("${file.upload.path}") - private String uploadPath; - @Autowired private JwtUtil jwtUtil; @Autowired @@ -46,7 +41,9 @@ public class ManageSnController { @PostMapping("/tablet/upload_avatar") public Result uploadAvatar(@RequestParam("file") MultipartFile multipartFile) { - String avatarPath = uploadPath + File.separator + FilePath.TABLET_PATH + File.separator + FilePath.AVATAR_PATH + File.separator; + String projectPath = System.getProperty("user.dir"); + + String avatarPath = projectPath + File.separator + FilePath.getAvatarPath(); File fileDir = new File(avatarPath); if (!fileDir.exists()) { diff --git a/src/main/resources/application-debug.properties b/src/main/resources/application-debug.properties index e9bb760..24eea01 100644 --- a/src/main/resources/application-debug.properties +++ b/src/main/resources/application-debug.properties @@ -1,6 +1,5 @@ spring.application.name=VideoTablet server.port=8088 -file.upload.path=/data/uploads/ ## mysql 数据连接信息 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index d39b3dd..20471ef 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -1,6 +1,5 @@ spring.application.name=VideoTablet server.port=8088 -file.upload.path=/data/uploads/ ## mysql 数据连接信息 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties index d39b3dd..20471ef 100644 --- a/src/main/resources/application-test.properties +++ b/src/main/resources/application-test.properties @@ -1,6 +1,5 @@ spring.application.name=VideoTablet server.port=8088 -file.upload.path=/data/uploads/ ## mysql 数据连接信息 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver