@ApiOperation("이미지 조회")
@GetMapping("/{filename}", produces = [MediaType.IMAGE_JPEG_VALUE])
@ResponseStatus(HttpStatus.OK)
public byte[] viewImage(
@PathVariable filename: String
) {
return service.viewImage(filename)
}
public byte[] viewImage(String filename) {
try (
FileInputStream inputStream = new FileInputStream(filename);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()
) {
byte[] buffer = new byte[8192];
int length;
while ((length = inputStream.read(buffer)) != -1)
outputStream.write(buffer, 0, length);
return outputStream.toByteArray();
} catch (IOException e) {
throw new CannotViewImageException();
}
}