@Slf4j @Controller @RequestMapping("/servlet/v2") public class ServletUploadControllerV2 {
@Value("${file.dir}") private String fileDir;
@GetMapping("/upload") public String newFile() { return "upload-form"; }
@PostMapping("/upload") public String saveFileV1(HttpServletRequest request) throws ServletException, IOException { log.info("request={}", request);
String itemName = request.getParameter("itemName"); log.info("itemName={}", itemName);
Collection<Part> parts = request.getParts(); log.info("parts={}", parts);
for (Part part : parts) { log.info("==== PART ===="); log.info("name={}", part.getName()); Collection<String> headerNames = part.getHeaderNames(); for (String headerName : headerNames) { log.info("header {}: {}", headerName, part.getHeader(headerName)); } log.info("submittedFilename={}", part.getSubmittedFileName()); log.info("size={}", part.getSize());
InputStream inputStream = part.getInputStream(); String body = StreamUtils.copyToString(inputStream, StandardCharsets.UTF_8); log.info("body={}", body);
if (StringUtils.hasText(part.getSubmittedFileName())) { String fullPath = fileDir + part.getSubmittedFileName(); log.info("파일 저장 fullPath={}", fullPath); part.write(fullPath); } }
return "upload-form"; } }
|