1
클라이언트 측에서 이미지를 너비와 높이 250px로 잘라냅니다. 이미지를 base64로 보냅니다. Cropper의 결과는 항상 base64이며,이 여러 부분으로 나누고 싶은 경우에 몇 가지 문제가 있습니다.Base64 업로드 성능
누군가가 이미지를 직접 업로드하거나 api를 직접 사용하는 경우에 대비하여 이미지를 컨트롤러에 전달하고이를 관리하는 성능이 궁금합니다.
이미지 업로드, 관리 및 유효성 검사의 올바른 방법입니까?
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public @ResponseBody ResponseEntity<?> upload(@RequestParam("imageValue") String imageValue, HttpServletRequest request) {
try {
String splitter = ";base64,";
String[] splitted = imageValue.split(splitter);
if (splitted.length != 2)
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
byte[] imageByte = Base64.decodeBase64(splitted[1]);
ByteArrayInputStream bis = new ByteArrayInputStream(imageByte);
BufferedImage image = ImageIO.read(bis);
if (image == null || image.getHeight() > 250 || image.getWidth() > 250)
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
FooImageData fooImageData = new FooImageData();
fooImageData.setBase64(imageByte);
fooImageData.setMimeType(splitted[0] + splitter);
fooImageDataService.save(fooImageData);
bis.close();
return new ResponseEntity<>(HttpStatus.OK);
} catch (Exception e) {
e.printStackTrace();
}
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
POST 매개 변수는 요청 본문에 전달됩니다. – EJP