配置从公网访问文件,优化图片上传
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
// 文件操作逻辑...
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
@@ -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/");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user