|
@@ -17,8 +17,10 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.yaml.snakeyaml.util.UriEncoder;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.OutputStream;
|
|
|
import java.nio.file.Files;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Objects;
|
|
@@ -43,45 +45,61 @@ public class ApiController extends BaseController {
|
|
|
@Resource
|
|
|
private ISysConfigService configService;
|
|
|
|
|
|
- /**
|
|
|
- * 文件下载
|
|
|
- *
|
|
|
- * @param fileId fileId
|
|
|
- * @return
|
|
|
- */
|
|
|
- @ApiOperation("文件预览")
|
|
|
- @GetMapping("/access/{fileId}")
|
|
|
- public ResponseEntity<Object> access(@PathVariable(name = "fileId") String fileId) {
|
|
|
- return down(fileId, false);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 文件下载
|
|
|
- *
|
|
|
- * @param fileId fileId
|
|
|
- * @return
|
|
|
- */
|
|
|
- @ApiOperation("文件下载")
|
|
|
- @GetMapping("/download/{fileId}")
|
|
|
- public ResponseEntity<Object> download(@PathVariable(name = "fileId") String fileId) {
|
|
|
- return down(fileId, true);
|
|
|
- }
|
|
|
-
|
|
|
- private ResponseEntity<Object> down(String fileId, boolean down) {
|
|
|
- DocumentVO vo = mongoService.downloadFile(fileId);
|
|
|
- if (Objects.nonNull(vo)) {
|
|
|
- String disposition = down ? "attachment" : "inline";
|
|
|
- disposition += "; filename=\"" + UriEncoder.encode(vo.getFileName()) + "\"";
|
|
|
- return ResponseEntity.ok()
|
|
|
- .header(HttpHeaders.CONTENT_DISPOSITION, disposition)
|
|
|
- .header(HttpHeaders.CONTENT_TYPE, vo.getContentType())
|
|
|
- .header(HttpHeaders.CONTENT_LENGTH, vo.getFileSize() + "")
|
|
|
- .header("Connection", "close")
|
|
|
- .body(vo.getData());
|
|
|
- } else {
|
|
|
- return ResponseEntity.status(HttpStatus.NOT_FOUND).body("file does not exist");
|
|
|
- }
|
|
|
- }
|
|
|
+// /**
|
|
|
+// * 文件下载
|
|
|
+// *
|
|
|
+// * @param fileId fileId
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// @ApiOperation("文件预览")
|
|
|
+// @GetMapping("/access/{fileId}")
|
|
|
+// public ResponseEntity<Object> access(@PathVariable(name = "fileId") String fileId) {
|
|
|
+// return down(fileId, false);
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 文件下载
|
|
|
+// *
|
|
|
+// * @param fileId fileId
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// @ApiOperation("文件下载")
|
|
|
+// @GetMapping("/download/{fileId}")
|
|
|
+// public ResponseEntity<Object> download(@PathVariable(name = "fileId") String fileId) {
|
|
|
+// return down(fileId, true);
|
|
|
+// }
|
|
|
+//
|
|
|
+// private ResponseEntity<Object> down(String fileId, boolean down) {
|
|
|
+// DocumentVO vo = mongoService.downloadFile(fileId);
|
|
|
+// if (Objects.nonNull(vo)) {
|
|
|
+// String disposition = down ? "attachment" : "inline";
|
|
|
+// disposition += "; filename=\"" + UriEncoder.encode(vo.getFileName()) + "\"";
|
|
|
+// return ResponseEntity.ok()
|
|
|
+// .header(HttpHeaders.CONTENT_DISPOSITION, disposition)
|
|
|
+// .header(HttpHeaders.CONTENT_TYPE, vo.getContentType())
|
|
|
+// .header(HttpHeaders.CONTENT_LENGTH, vo.getFileSize() + "")
|
|
|
+// .header("Connection", "close")
|
|
|
+// .body(vo.getData());
|
|
|
+// } else {
|
|
|
+// return ResponseEntity.status(HttpStatus.NOT_FOUND).body("file does not exist");
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// @ApiOperation("文件下载")
|
|
|
+// @GetMapping("/down/{fileId}")
|
|
|
+// public void download(@PathVariable(name = "fileId") String fileId, HttpServletResponse response) {
|
|
|
+// DocumentVO vo = mongoService.downloadFile(fileId);
|
|
|
+// response.setContentType(vo.getContentType());
|
|
|
+// response.setHeader("Content-Disposition", "attachment; filename=\"" + UriEncoder.encode(vo.getFileName()) + "\"");
|
|
|
+// response.addHeader("Content-Length", "" + vo.getFileSize());
|
|
|
+//
|
|
|
+// try (OutputStream stream = response.getOutputStream()) {
|
|
|
+// stream.write(vo.getData());
|
|
|
+// stream.flush();
|
|
|
+// } catch (IOException e) {
|
|
|
+// throw new RuntimeException(e);
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
|
* 文字识别
|