Parcourir la source

修改 FileMessageConverter 中临时上传文件存储的位置

reghao il y a 3 ans
Parent
commit
9ddd44258b

+ 4 - 1
src/main/java/cn/reghao/dfs/store/config/FileMessageConverter.java

@@ -9,6 +9,7 @@ import org.springframework.http.converter.HttpMessageNotReadableException;
 import org.springframework.http.converter.HttpMessageNotWritableException;
 
 import java.io.*;
+import java.util.UUID;
 
 /**
  * 实现 PUT 请求上传文件
@@ -31,7 +32,9 @@ public class FileMessageConverter extends AbstractHttpMessageConverter<File> {
             throws IOException, HttpMessageNotReadableException {
 
         InputStream inputStream = inputMessage.getBody();
-        File tmpFile = File.createTempFile("upload",".dat");
+        String tmpPath = String.format("/opt/tmp/tomcat/%s.dat", UUID.randomUUID());
+        File tmpFile = new File(tmpPath);
+        tmpFile.createNewFile();
         if (inputStream != null) {
             FileOutputStream outputStream = new FileOutputStream(tmpFile);