From 92cb08328be54933778176ed2ec594d42c0a0a1f Mon Sep 17 00:00:00 2001 From: "pixeebot[bot]" <104101892+pixeebot[bot]@users.noreply.github.com> Date: Sun, 12 Jan 2025 03:08:13 +0000 Subject: [PATCH] Modernize and secure temp file creation --- .../main/java/com/yupi/web/controller/FileController.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/yuzi-generator-web-backend/src/main/java/com/yupi/web/controller/FileController.java b/yuzi-generator-web-backend/src/main/java/com/yupi/web/controller/FileController.java index 4a419f1..44c96c2 100644 --- a/yuzi-generator-web-backend/src/main/java/com/yupi/web/controller/FileController.java +++ b/yuzi-generator-web-backend/src/main/java/com/yupi/web/controller/FileController.java @@ -15,6 +15,7 @@ import com.yupi.web.model.entity.User; import com.yupi.web.model.enums.FileUploadBizEnum; import com.yupi.web.service.UserService; +import java.nio.file.Files; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.RandomStringUtils; import org.springframework.web.bind.annotation.*; @@ -59,7 +60,7 @@ public BaseResponse testUploadFile(@RequestPart("file") MultipartFile mu File file = null; try { // 上传文件 - file = File.createTempFile(filepath, null); + file = Files.createTempFile(filepath, null).toFile(); multipartFile.transferTo(file); cosManager.putObject(filepath, file); // 返回可访问地址 @@ -135,7 +136,7 @@ public BaseResponse uploadFile(@RequestPart("file") MultipartFile multip File file = null; try { // 上传文件 - file = File.createTempFile(filepath, null); + file = Files.createTempFile(filepath, null).toFile(); multipartFile.transferTo(file); cosManager.putObject(filepath, file); // 返回可访问地址