| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | |
| | | // 上传到临时目录 |
| | | @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); |
| | | Path tempFilePath = Paths.get(tempDir, tempId + "_" + encodedFilename); |
| | | |
| | | // Path tempFilePath = Paths.get(tempDir, tempId + "_" + file.getOriginalFilename()); |
| | | |
| | | // 2. 确保目录存在 |
| | | Path parentDir = tempFilePath.getParent(); |