오늘 한 일

  • 인프런 스프링 MVC 2편 - 백엔드 웹 개발 활용 기술 파일 업로드 부분 수강
  • 사이드 프로젝트에 파일 업로드, 다운로드 구현


이클립스 Slf4j log 에러처리

Slf4j log cannot be resolved

  • 전자정부프레임워크에서 lombok 라이브러리가 제대로 설치되지 않아서 생기는 문제였다.
  • 마침 나도 블로그와 같은 전자정부프레임워크 버전을 사용하고 있어서 쉽게 해결했다. 이 버전의 문제일까?
  • 이클립스 Slf4j 에러처리

파일 업로드 옵션 설정

  • application.properties 파일에 파일 업로드 관련 설정을 추가했다.

  • max-file-size : 파일 1개의 최대 크기

  • max-request-size : 멀티파트 요청 하나의 모든 파일 크기 합의 최대값 (기본 10MB)

  • 나는 D드라이브에 파일을 저장하려고 경로에 드라이브까지 적어주었다. D드라이브 파일경로 설정

    Windows™: drive:\ProgramFiles\IBM\WebSphere\AppServer
    where drive is the system drive on which the file directory is stored. For example: C or D.

  • spring.servlet.multipart.enabled=false 멀티파트 처리 여부 (기본값 true)

// application.properties
# 파일 업로드 사이즈 제한
spring.servlet.multipart.max-file-size=1MB
spring.servlet.multipart.max-request-size=10MB

# 파일 업로드 경로
file.dir=D:/practice/file/

spring.servlet.multipart.enabled=false

application.properties 속성값 java로 가져오기

import org.springframework.beans.factory.annotation.Value;
// application.properties의 속성값 그대로 가져오기
@Value("${file.dir}")
String fileDir;

@RequiredArgsConstructor

  • 초기화되지 않은 final 필드나 @NonNull이 붙은 필드에 대해 생성자 생성

파일 여러 개 업로드

  • html input - multiple="multiple"

구현 순서

  1. domain : 첨부파일정보 Attach, 게시물 Post
  2. repository
  3. storeFile
  4. controller url까지
  5. url에 해당하는 html 생성
  6. controller 완성
profile
문서화를 좋아하는 개발자

0개의 댓글