fix - 限制上传文件大小

This commit is contained in:
2026-05-19 15:01:16 +08:00
parent 44f867a606
commit 0907912773
2 changed files with 14 additions and 4 deletions

View File

@@ -1 +1,5 @@
{"serverIp":"127.0.0.1","serverPort":"56791","clientSN":"MC-5824T23014127","clientVid":"41"} {"serverIp":"127.0.0.1","serverPort":"56791","clientSN":"MC-5824T23014127","clientVid":"41"}
-- 如果要改篮球馆的id
update sv_venue set `id` = 60 where `id` = 1;
update sv_venue_image set venue_id = 60 where venue_id = 1;
update sv_venue_price set venue_id = 60 where venue_id = 1;

View File

@@ -1,17 +1,15 @@
package com.sv.oms.controller; package com.sv.oms.controller;
import com.sv.exception.oms.OmsException;
import com.sv.service.common.OSSClientUtil; import com.sv.service.common.OSSClientUtil;
import com.ydd.framework.core.common.dto.ResponseDTO; import com.ydd.framework.core.common.dto.ResponseDTO;
import com.ydd.oms.controller.OmsController; import com.ydd.oms.controller.OmsController;
import org.apache.http.HttpRequest;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException; import java.io.IOException;
@RestController("upload") @RestController("upload")
@@ -24,6 +22,11 @@ public class UploadController extends OmsController {
@RequestMapping("/image") @RequestMapping("/image")
public ResponseDTO uploadImg(@RequestParam("file") MultipartFile file) throws IOException { public ResponseDTO uploadImg(@RequestParam("file") MultipartFile file) throws IOException {
// 检查文件大小是否超过1MB
if (file.getSize() > 1 * 1024 * 1024) {
throw new OmsException("文件大小不能超过1MB");
}
String imgUrl = ossClientUtil.uploadConfigImg(file); String imgUrl = ossClientUtil.uploadConfigImg(file);
return ResponseDTO.ok().addAttribute("img",imgUrl); return ResponseDTO.ok().addAttribute("img",imgUrl);
} }
@@ -56,6 +59,9 @@ public class UploadController extends OmsController {
*/ */
@RequestMapping(value = "/uploadFile") @RequestMapping(value = "/uploadFile")
public ResponseDTO uploadFile(@RequestParam("file") MultipartFile multipartFile) throws IOException { public ResponseDTO uploadFile(@RequestParam("file") MultipartFile multipartFile) throws IOException {
if (multipartFile.getSize() > 20 * 1024 * 1024) {
throw new OmsException("健康报告文件大小不能超过20MB");
}
String healthUrl = ossClientUtil.uploadHealth(multipartFile); String healthUrl = ossClientUtil.uploadHealth(multipartFile);
return ResponseDTO.ok().addAttribute("docPath",healthUrl); return ResponseDTO.ok().addAttribute("docPath",healthUrl);
} }