Replies: 1 comment
-
🎤 Q. Spring에서 파일 업로드는 어떻게 처리되나요?Spring에서는 ✅ 기본 흐름
✅ 실습 예시HTML <form method="post" enctype="multipart/form-data" action="/upload">
<input type="file" name="file"/>
<input type="submit" value="업로드"/>
</form>Controller @PostMapping("/upload")
public String upload(@RequestParam("file") MultipartFile file) throws IOException {
String savedName = UUID.randomUUID() + "_" + file.getOriginalFilename();
Path savePath = Paths.get("C:/upload/" + savedName);
file.transferTo(savePath.toFile());
return "uploadSuccess";
}✅ 파일명 중복 방지
✅ 설정 예시 (application.properties) spring.servlet.multipart.enabled=true
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=20MB✅ 보안 고려사항
✅ 추가 팁
📌 이처럼 Spring에서는 MultipartFile을 활용한 파일 업로드를 구조적으로 처리하며, 보안과 확장성까지 고려한 설계가 중요합니다. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
📷
Beta Was this translation helpful? Give feedback.
All reactions