From 5068dca753e3c628190ee68fd8729989b818ba5b Mon Sep 17 00:00:00 2001 From: shinmj Date: Fri, 19 Nov 2021 10:40:12 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B3=B4=EC=95=88=EC=A0=90=EA=B2=80=20?= =?UTF-8?q?=EC=88=98=EC=A0=95(ftpstorageutils)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../portalservice/utils/FtpStorageUtils.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/backend/portal-service/src/main/java/org/egovframe/cloud/portalservice/utils/FtpStorageUtils.java b/backend/portal-service/src/main/java/org/egovframe/cloud/portalservice/utils/FtpStorageUtils.java index 6cd2497..268294a 100644 --- a/backend/portal-service/src/main/java/org/egovframe/cloud/portalservice/utils/FtpStorageUtils.java +++ b/backend/portal-service/src/main/java/org/egovframe/cloud/portalservice/utils/FtpStorageUtils.java @@ -367,21 +367,21 @@ public class FtpStorageUtils implements StorageUtils { * @throws IOException */ public AttachmentImageResponseDto loadImage(String imagename) { + InputStream inputStream = null; try { - String paths = environment.getProperty("file.url") + imagename; + String paths = environment.getProperty("file.url")+StringUtils.cleanPath("/"+ imagename); Resource resource = new UrlResource(paths); - InputStream inputStream = resource.getInputStream(); + inputStream = resource.getInputStream(); byte[] data = IOUtils.toByteArray(inputStream); + String contentType = URLConnection.guessContentTypeFromName(resource.getFilename()); + inputStream.close(); - // get mime type - String contentType = Files.probeContentType(resource.getFile().toPath()); - return AttachmentImageResponseDto.builder() - .mimeType(contentType) - .data(data) - .build(); + .mimeType(contentType) + .data(data) + .build(); } catch (FileNotFoundException | NoSuchFileException ex) { // 파일을 찾을 수 없습니다. throw new BusinessMessageException(messageUtil.getMessage("valid.file.not_found")); @@ -389,6 +389,14 @@ public class FtpStorageUtils implements StorageUtils { log.error("Could not read file.", iex); // 파일을 찾을 수 없습니다. throw new BusinessMessageException(messageUtil.getMessage("valid.file.not_found")); + }finally { + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException e) { + log.error(e.getLocalizedMessage()); + } + } } }