|
@@ -5,14 +5,18 @@ import org.apache.log4j.LogManager;
|
|
import org.apache.log4j.Logger;
|
|
import org.apache.log4j.Logger;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
|
+import org.springframework.http.MediaType;
|
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import java.io.File;
|
|
|
|
-import java.io.FileOutputStream;
|
|
|
|
-import java.io.InputStream;
|
|
|
|
-import java.io.OutputStream;
|
|
|
|
|
|
+import java.io.*;
|
|
|
|
+import java.net.URLEncoder;
|
|
|
|
+import java.nio.file.Files;
|
|
|
|
+import java.nio.file.Path;
|
|
|
|
+import java.nio.file.Paths;
|
|
import java.util.UUID;
|
|
import java.util.UUID;
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
@@ -26,6 +30,9 @@ public class CommonUploadController {
|
|
@Value(value = "${upload.tempUpdatePath}")
|
|
@Value(value = "${upload.tempUpdatePath}")
|
|
private String tempUpdatePath;
|
|
private String tempUpdatePath;
|
|
|
|
|
|
|
|
+ @Value(value = "${logging.path}")
|
|
|
|
+ private String logPath;
|
|
|
|
+
|
|
@RequestMapping(value="uploadFile")
|
|
@RequestMapping(value="uploadFile")
|
|
public HttpRespMsg uploadFile(MultipartFile multipartFile) {
|
|
public HttpRespMsg uploadFile(MultipartFile multipartFile) {
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
@@ -97,4 +104,25 @@ public class CommonUploadController {
|
|
|
|
|
|
return msg;
|
|
return msg;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @RequestMapping("/downLoadLog")
|
|
|
|
+ public ResponseEntity<byte[]> downLoadLog() throws IOException {
|
|
|
|
+ // 🧐🧐🧐读取本地的文件
|
|
|
|
+ // 获取File对象
|
|
|
|
+ System.out.println("读取目录=="+logPath);
|
|
|
|
+ logger.info("读取目录=={}"+logPath);
|
|
|
|
+ String fileName = "workshop.out";
|
|
|
|
+ File readFile=new File(logPath+fileName);
|
|
|
|
+ // 🐳🐳🐳设置响应头,把文件名称放入响应头中,确保文件可下载
|
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
|
+ headers.set("Content-Disposition", "attachment;filename=" + URLEncoder.encode(readFile.getName(), "UTF-8"));
|
|
|
|
+ // 🐳🐳🐳设置内容类型为「application/octet-stream」二进制流
|
|
|
|
+ headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
|
|
|
+
|
|
|
|
+ Path path = Paths.get(readFile.toURI());
|
|
|
|
+ // 获取File对象的字节码文件
|
|
|
|
+ byte[] bytes = Files.readAllBytes(path);
|
|
|
|
+ //return new ResponseEntity<>(bytes, headers, HttpStatus.OK);
|
|
|
|
+ return ResponseEntity.ok().headers(headers).body(bytes);
|
|
|
|
+ }
|
|
}
|
|
}
|