Quantcast
Channel: Active questions tagged servlets - Stack Overflow
Viewing all articles
Browse latest Browse all 675

CORS Error when uploading larger file (MultipartFile) in Spring Boot Web API

$
0
0

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]

Viewing all articles
Browse latest Browse all 675

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>