//Save the uploaded file to this folder private static String UPLOADED_FOLDER = "D://temp//";
@GetMapping("/") public String index() { return "upload"; }
@PostMapping("/upload") // //new annotation since 4.3 public String singleFileUpload(@RequestParam("file") MultipartFile file, RedirectAttributes redirectAttributes) {
if (file.isEmpty()) { redirectAttributes.addFlashAttribute("message", "Please select a file to upload"); return "redirect:uploadStatus"; }
try {
// Get the file and save it somewhere byte[] bytes = file.getBytes(); Path path = Paths.get(UPLOADED_FOLDER + file.getOriginalFilename()); Files.write(path, bytes);
2017-03-30 23:40:04 INFO com.yiibai.SpringBootWebApplication - Starting SpringBootWebApplication on MY-PC with PID 880 (F:\worksp\springboot\file-upload\target\classes started by Administrator in F:\worksp\springboot\file-upload) 2017-03-30 23:40:04 DEBUG com.yiibai.SpringBootWebApplication - Running with Spring Boot v1.4.3.RELEASE, Spring v4.3.5.RELEASE 2017-03-30 23:40:04 INFO com.yiibai.SpringBootWebApplication - No active profile set, falling back to default profiles: default 2017-03-30 23:40:08 INFO com.yiibai.SpringBootWebApplication - Started SpringBootWebApplication in 5.359 seconds (JVM running for 6.355)