ImageManager - 12월 22일

yshjft·2022년 12월 22일
0

ImageManager

목록 보기
3/3

RequestParam을 이용해 파일 전달 받기

@PostMapping
public ResponseEntity<ApiResponse<String>> createPost(
            @ModelAttribute @Valid PostCreateRequest postCreateRequest,
            @RequestParam("files") List<MultipartFile> files
) {
	...
}

파일 사이즈 제한하기

  • application.yml
spring:
  servlet:
    multipart:
      enabled: true
      max-file-size: 5MB
      max-request-size: 15MB
  • GlobalExceptionHandler.java
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(MaxUploadSizeExceededException.class)
	...
    
    public ResponseEntity<ErrorResponse> handleMaxUploadSizeExceededException(MaxUploadSizeExceededException e) {
        return createErrorResponseEntity(e, MAX_UPLOAD_SIZE_EXCEEDED);
    }
}

MultipartFile 파일 이름 가져오기

MultipartFile 파일 이름 가져오기 참고

profile
꾸준히 나아가자 🐢

0개의 댓글