I have the below API to save MultipartFile. I am able to save files if the file size is below the defined limit.
@PostMapping("/attachments") @Operation(summary = "save attachments") public ResponseEntity<List<Attachment>> saveAttachments(@RequestParam ("files") MultipartFile[] files,@RequestParam ("id") Long id) { return ResponseEntity.ok(myservice.saveAttachment(id, files)); }
Below is my properties file:
spring.servlet.multipart.enabled=truespring.servlet.multipart.file-size-threshold=2KBspring.servlet.multipart.max-file-size=10MBspring.servlet.multipart.max-request-size=200MB
Now, If I upload anything below 10MB it works fine without any errors. But, when I try to upload any file above 10MB then I am getting a CORS policy error (I have already defined CORS policy).
Access to XMLHttpRequest at 'http://localhost:8002/api/attachments' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I am handling file size exception and getting below exception handling message in backend:
Resolved [org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded]