liyong
昨天 ba4af275c3b8d073f863be7b12e43974b3ef14a2
src/main/java/com/ruoyi/other/service/impl/TempFileServiceImpl.java
@@ -6,6 +6,7 @@
import com.ruoyi.other.pojo.TempFile;
import com.ruoyi.other.service.TempFileService;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.util.URLEncoder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
@@ -13,6 +14,7 @@
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -32,10 +34,17 @@
    // 上传到临时目录
    @Override
    public TempFile uploadFile(MultipartFile file,String type) throws IOException {
    public TempFile uploadFile(MultipartFile file,Integer type) throws IOException {
        // 1. 生成临时文件ID和路径
        String tempId = UUID.randomUUID().toString();
        Path tempFilePath = Paths.get(tempDir, tempId + "_" + file.getOriginalFilename());
        String originalFilename = file.getOriginalFilename();
        if(originalFilename == null) throw new IOException("文件名不能为空");
        URLEncoder urlEncoder = new URLEncoder();
        String encodedFilename = urlEncoder.encode(originalFilename, StandardCharsets.UTF_8);
        encodedFilename = encodedFilename.replaceAll("%2E",".");
        Path tempFilePath = Paths.get(tempDir, tempId + "_" + encodedFilename);
//        Path tempFilePath = Paths.get(tempDir, tempId + "_" + file.getOriginalFilename());
        // 2. 确保目录存在
        Path parentDir = tempFilePath.getParent();