From 44e994e9d3d39dec4d9995a77082b052523509fc Mon Sep 17 00:00:00 2001 From: zhaowenxuan <chacca165@163.com> Date: 星期日, 27 四月 2025 18:17:47 +0800 Subject: [PATCH] 上传问题查看接口 --- ltkj-admin/src/main/java/com/ltkj/web/controller/ProfileuploadController.java | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 53 insertions(+), 0 deletions(-) diff --git a/ltkj-admin/src/main/java/com/ltkj/web/controller/ProfileuploadController.java b/ltkj-admin/src/main/java/com/ltkj/web/controller/ProfileuploadController.java new file mode 100644 index 0000000..7c1ddcb --- /dev/null +++ b/ltkj-admin/src/main/java/com/ltkj/web/controller/ProfileuploadController.java @@ -0,0 +1,53 @@ +package com.ltkj.web.controller; + +import com.ltkj.common.config.ltkjConfig; +import io.lettuce.core.dynamic.annotation.Value; +import org.springframework.core.io.Resource; +import org.springframework.core.io.UrlResource; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.net.MalformedURLException; +import java.nio.file.Path; +import java.nio.file.Paths; + +/** + * @Company: 瑗垮畨璺嘲绉戞妧鏈夐檺鍏徃 + * @Author: zhaowenxuan + * @Date: 2025/4/27 18:03 + */ +@RestController +@RequestMapping("/profileupload") +public class ProfileuploadController { + + + @GetMapping("/{type}/{year}/{month}/{day}/{filename:.+}") + public ResponseEntity<Resource> getFile( + @PathVariable String type, + @PathVariable String year, + @PathVariable String month, + @PathVariable String day, + @PathVariable String filename) { + try { + // 鎷兼帴瀹屾暣璺緞 + Path filePath = Paths.get(ltkjConfig.getUploadPath(),type, year, month, day, filename); + Resource resource = new UrlResource(filePath.toUri()); + + if (!resource.exists()) { + return ResponseEntity.notFound().build(); + } + + return ResponseEntity.ok() + .header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + resource.getFilename() + "\"") + .contentType(MediaType.IMAGE_JPEG) // 杩欓噷榛樿鍥剧墖鏄痡pg锛屽鏋滄湁鍒殑绫诲瀷鍙互鍔犲垽鏂� + .body(resource); + } catch (MalformedURLException e) { + return ResponseEntity.badRequest().build(); + } + } +} -- Gitblit v1.8.0