Browse Source

获取到需上传的pdf文件

master
liwenxuan 7 months ago
parent
commit
e94a1ba4b9
  1. 10
      src/main/java/com/hxjt/dataupload/controller/UploadController.java

10
src/main/java/com/hxjt/dataupload/controller/UploadController.java

@ -93,7 +93,11 @@ private FxfxdxService fxfxdxService;
} }
@PostMapping("/uploadPDF") @PostMapping("/uploadPDF")
public ResponseEntity<String> uploadPdf(@RequestParam("file") MultipartFile file) { public ResponseEntity<String> uploadPdf(
@RequestParam("file") MultipartFile file,
@RequestParam("id") String id,
@RequestParam("ticketNumber") String ticketNumber) {
//上线
String uploadDir = "F://dataUpload/zypPdfs/"; String uploadDir = "F://dataUpload/zypPdfs/";
// 1. 验证文件类型和大小 // 1. 验证文件类型和大小
if (file.isEmpty()) { if (file.isEmpty()) {
@ -105,6 +109,8 @@ private FxfxdxService fxfxdxService;
if (file.getSize() > 10 * 1024 * 1024) { // 限制10MB if (file.getSize() > 10 * 1024 * 1024) { // 限制10MB
return ResponseEntity.badRequest().body("文件大小超过限制"); return ResponseEntity.badRequest().body("文件大小超过限制");
} }
System.out.println(id);
System.out.println(ticketNumber);
try { try {
// 确保目录存在 // 确保目录存在
@ -114,7 +120,7 @@ private FxfxdxService fxfxdxService;
} }
// 生成唯一文件名(可选,避免重复覆盖) // 生成唯一文件名(可选,避免重复覆盖)
String fileName = UUID.randomUUID() + "_" + file.getOriginalFilename(); String fileName = id+ "_" +ticketNumber+".pdf";
// 构建目标文件的绝对路径 // 构建目标文件的绝对路径
File targetFile = new File(targetDir.getAbsolutePath() + File.separator + fileName); File targetFile = new File(targetDir.getAbsolutePath() + File.separator + fileName);

Loading…
Cancel
Save