소스 검색

将图片上传到临时目录

humuyu 3 년 전
부모
커밋
53e46e9091
1개의 변경된 파일20개의 추가작업 그리고 2개의 파일을 삭제
  1. 20 2
      eladmin-system/src/main/java/me/zhengjie/appapi/util/FileUploadUtil.java

+ 20 - 2
eladmin-system/src/main/java/me/zhengjie/appapi/util/FileUploadUtil.java

@@ -14,6 +14,7 @@ import javax.imageio.stream.ImageInputStream;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.boot.web.server.WebServerException;
 import org.springframework.web.multipart.MultipartFile;
 
 import cn.hutool.core.io.IoUtil;
@@ -400,12 +401,29 @@ public class FileUploadUtil {
 //			return null;
 //		}
 //	}
-
+	/**
+	 * Return the absolute temp dir for given web server.
+	 * @param prefix server name
+	 * @return the temp dir for given server.
+	 */
+	public static String createTempDir(String temp) {
+		try {
+			File tempDir = File.createTempFile("eladmin",temp);
+			tempDir.delete();
+			tempDir.mkdir();
+			tempDir.deleteOnExit();
+			return tempDir.getAbsolutePath()+"/";
+		}
+		catch (IOException ex) {
+			throw new WebServerException(
+					"Unable to create tempDir. java.io.tmpdir is set to " + System.getProperty("java.io.tmpdir"), ex);
+		}
+	}
 	public static String savePdf(String html, String businessNo, String orderId) {
 		if (html == null) {
 			return null;
 		}
-		String uploadPath = AppConfigInfo.APP_UPLOAD_PATH;
+		String uploadPath = createTempDir("upload");
 		// 拼接文件路径
 		String fileName = UUIDGenerator.uuid() + ".pdf";
 		String path = businessNo + "/" + StepStatusEnum.getType(orderId) + "/" + fileName;