보안점검 수정(ftpstorageutils)
This commit is contained in:
@@ -367,21 +367,21 @@ public class FtpStorageUtils implements StorageUtils {
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public AttachmentImageResponseDto loadImage(String imagename) {
|
public AttachmentImageResponseDto loadImage(String imagename) {
|
||||||
|
InputStream inputStream = null;
|
||||||
try {
|
try {
|
||||||
String paths = environment.getProperty("file.url") + imagename;
|
String paths = environment.getProperty("file.url")+StringUtils.cleanPath("/"+ imagename);
|
||||||
Resource resource = new UrlResource(paths);
|
Resource resource = new UrlResource(paths);
|
||||||
InputStream inputStream = resource.getInputStream();
|
inputStream = resource.getInputStream();
|
||||||
|
|
||||||
byte[] data = IOUtils.toByteArray(inputStream);
|
byte[] data = IOUtils.toByteArray(inputStream);
|
||||||
|
String contentType = URLConnection.guessContentTypeFromName(resource.getFilename());
|
||||||
|
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
|
|
||||||
// get mime type
|
|
||||||
String contentType = Files.probeContentType(resource.getFile().toPath());
|
|
||||||
|
|
||||||
return AttachmentImageResponseDto.builder()
|
return AttachmentImageResponseDto.builder()
|
||||||
.mimeType(contentType)
|
.mimeType(contentType)
|
||||||
.data(data)
|
.data(data)
|
||||||
.build();
|
.build();
|
||||||
} catch (FileNotFoundException | NoSuchFileException ex) {
|
} catch (FileNotFoundException | NoSuchFileException ex) {
|
||||||
// 파일을 찾을 수 없습니다.
|
// 파일을 찾을 수 없습니다.
|
||||||
throw new BusinessMessageException(messageUtil.getMessage("valid.file.not_found"));
|
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);
|
log.error("Could not read file.", iex);
|
||||||
// 파일을 찾을 수 없습니다.
|
// 파일을 찾을 수 없습니다.
|
||||||
throw new BusinessMessageException(messageUtil.getMessage("valid.file.not_found"));
|
throw new BusinessMessageException(messageUtil.getMessage("valid.file.not_found"));
|
||||||
|
}finally {
|
||||||
|
if (inputStream != null) {
|
||||||
|
try {
|
||||||
|
inputStream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error(e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user