瀏覽代碼

修改下载文件的BUG。

wukai 1 年之前
父節點
當前提交
a3facda8a5
共有 1 個文件被更改,包括 8 次插入2 次删除
  1. 8 2
      doc-biz/src/main/java/com/doc/biz/controller/ApiController.java

+ 8 - 2
doc-biz/src/main/java/com/doc/biz/controller/ApiController.java

@@ -70,8 +70,14 @@ public class ApiController extends BaseController {
     private ResponseEntity<Object> down(String fileId, boolean down) {
         DocumentVO vo = mongoService.downloadFile(fileId);
         if (Objects.nonNull(vo)) {
-            String disposition = down ? "attachment;" : "" + "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());
+            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");
         }