Spring Boot File upload

Use MultipartFile as parameter

Please use MultipartFile as parameter in Spring boot controller

Example

Controller

@RestController
public class ExampleController {

@RequestMapping(value = "/upload", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public String upload(UploadRequest uploadRequest) {
    
       MultipartFile file = uploadRequest.getFile1()[0];
       // If you want to save byte[] into DB
       // file.getBytes()
     
       return "Success";
    }
}

Data

@Data
public UploadRequest() {
   private MultipartFile[] file1;
}

@Data is from lombok

As for client side coding I will explain using Angular

コメント