修改上传文件配置

This commit is contained in:
闵宪瑞 2025-02-13 15:20:24 +08:00
parent f0925d2ed3
commit f8a32a672f
2 changed files with 10 additions and 5 deletions

View File

@ -21,17 +21,22 @@ import java.util.HashMap;
public class UploadController { public class UploadController {
@Value("${upload.path}") @Value("${upload.path}")
private String path; private String path;
@Value("${upload.url}")
private String uploadUrl;
@PostMapping() @PostMapping()
public Result upload(HttpServletRequest request,MultipartFile file) throws IOException { public Result upload(MultipartFile file) throws IOException {
if (file.isEmpty()) { if (file.isEmpty()) {
return new Result().error("文件不能为空!"); return new Result().error("文件不能为空!");
} }
//把文件的内容存储到本地磁盘上 //把文件的内容存储到本地磁盘上
String originFileName = file.getOriginalFilename(); String originFileName = file.getOriginalFilename();
file.transferTo(new File(path +"/"+ originFileName)); file.transferTo(new File(path +"/"+ originFileName));
String url = "http://localhost:18081/upload/" + originFileName; String url = uploadUrl + originFileName;
HashMap<String, String> map = new HashMap<>(); HashMap<String, String> map = new HashMap<>();
map.put("url",url);
return new Result<>().ok(url); map.put("path",url);
map.put("absolute","upload/" + originFileName);
return new Result<>().ok(map);
} }
} }

View File

@ -36,4 +36,4 @@ spring:
static-locations: "file:F:/upload/" static-locations: "file:F:/upload/"
upload: upload:
path: F:\upload path: F:\upload
url: https://bs.oss.xunyingcloud.cn/upload/movies/ url: https://localhost:10081/upload/