|
|
@@ -3,6 +3,7 @@ package cn.reghao.dfs.store.controller;
|
|
|
import cn.reghao.dfs.store.model.dto.PathUrl;
|
|
|
import cn.reghao.dfs.store.service.FileUrlService;
|
|
|
import cn.reghao.dfs.store.service.media.ImageFileService;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
import org.springframework.core.io.InputStreamResource;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
@@ -10,14 +11,13 @@ import org.springframework.http.MediaType;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.*;
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
|
|
|
/**
|
|
|
* @author reghao
|
|
|
* @date 2022-04-24 16:13:10
|
|
|
*/
|
|
|
+@Api(tags = "图片文件访问接口")
|
|
|
@RestController
|
|
|
@RequestMapping
|
|
|
public class ImageFileController {
|
|
|
@@ -29,26 +29,6 @@ public class ImageFileController {
|
|
|
this.imageFileService = imageFileService;
|
|
|
}
|
|
|
|
|
|
- @GetMapping("/image2/{filename}")
|
|
|
- @Deprecated
|
|
|
- public ResponseEntity<InputStreamResource> image2(@PathVariable("filename") String filename) throws Exception {
|
|
|
- String uploadId = filename.split("\\.")[0];
|
|
|
- PathUrl pathUrl = fileUrlService.getPathUrl(uploadId);
|
|
|
- if (pathUrl == null) {
|
|
|
- return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
|
|
|
- }
|
|
|
-
|
|
|
- String absolutePath = pathUrl.getAbsolutePath();
|
|
|
- FileInputStream fis = new FileInputStream(absolutePath);
|
|
|
- InputStreamResource inputStreamResource = new InputStreamResource(fis);
|
|
|
-
|
|
|
- HttpHeaders httpHeaders = new HttpHeaders();
|
|
|
- httpHeaders.set("Pragma", "No-cache");
|
|
|
- httpHeaders.set("Cache-Control", "no-cache");
|
|
|
- return ResponseEntity.status(HttpStatus.OK).headers(httpHeaders).contentType(MediaType.IMAGE_JPEG)
|
|
|
- .body(inputStreamResource);
|
|
|
- }
|
|
|
-
|
|
|
@GetMapping("/image/{filename:.+}")
|
|
|
public ResponseEntity<InputStreamResource> image(@PathVariable("filename") String filename) throws Exception {
|
|
|
String[] strs = filename.split("@");
|
|
|
@@ -66,6 +46,7 @@ public class ImageFileController {
|
|
|
String[] params = strs[1].split("_");
|
|
|
int width = Integer.parseInt(params[0].replace("w", ""));
|
|
|
int height = Integer.parseInt(params[1].replace("h", ""));
|
|
|
+ // TODO 在 response header 中会有 Content-Disposition inline;filename=f.txt 浏览器标签栏显示的名字是 f.txt
|
|
|
inputStream = imageFileService.getImageStream(absolutePath, width, height);
|
|
|
}
|
|
|
|