작성자 없음
작성자 정보가 삭제된 글입니다.
작성
·
405
0
이미지는 엑박으로 표기.
->새탭에서 이미지열기시, 나오는경로-
http://localhost:8080/images/C:/Users/계정/springfile/images/c3a2eedd-4364-4f3f-a275-a800512e4949.png
파일다운로드 클릭시 경로와 에러페이지,
http://localhost:8080/attach/C:/Users/계정/springfile/uploadfiles/9aa381e7-6b8d-412a-bf86-28caf5b29010.pdf
으로 됩니다.
----
save시 컴퓨터 경로에 사진, 파일이 저장이되고
db에도 잘 저장됩니다..
코드
<img th:each="imageFile : ${board.attachFiles}"
th:if="${imageFile.attachType.toString().equals('IMAGE')}"
th:src="|/images/${imageFile.storeFileName}|" width="300" height="300" style="margin-right: 5px"/>
<a th:each="uploadFile : ${board.attachFiles}"
th:if="${uploadFile.attachType.toString().equals('FILE')}"
th:href="@{/attach/{filename}(filename=${uploadFile.storeFileName}, originName=${uploadFile.uploadFileName})}"
th:text="${uploadFile.uploadFileName}" style="margin-right: 5px"/><br/>
@ResponseBody
@GetMapping("/images/{filename}")
public Resource processImg(@PathVariable String filename) throws MalformedURLException {
return new UrlResource("file:" + fileStore.getFullPath(filename, AttachType.IMAGE));
@GetMapping("/attach/{filename}")
public ResponseEntity<Resource> processAttaches(@PathVariable String filename, @RequestParam String originName) throws MalformedURLException {
UrlResource resource = new UrlResource("file:" + fileStore.getFullPath(filename, AttachType.FILE));
String encodedUploadFileName = UriUtils.encode(originName, StandardCharsets.UTF_8);
String contentDisposition = "attachment; filename=\"" + encodedUploadFileName + "\"";
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, contentDisposition)
.body(resource);
}