简体   繁体   中英

multipart/form-data post request getting CORS error with Angular 7 and spring boot, only when image size is more than 1 mb

I have a spring boot application where the controller is consuming the post request of content-type "multipart/form-data". This code is working when the image size is less than 1MB but if I upload any image of size more than 1MB, I always encounter this error. This error only appears in the production environment. In the local system, this is working perfectly fine. Error调用 API 时浏览器控制台出现 cors 错误

I have already increased the default size of the multipart file max size in the spring boot application property file.

#Spring max size upload
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=10MB
spring.servlet.multipart.enabled=true
    
#Server properties
server.tomcat.max-http-post-size=100000000
server.tomcat.max-swallow-size=100000000

Here is the Spring boot controller 弹簧启动控制器

I was using the Nginx for the load balancing that was the issue. When I increase the size of Nginx from AWS. The error got resolved.

I followed this blog to increase the size. You must need the root permission to update your Nginx configuration file

https://medium.com/@ghazaltaimur27/change-file-upload-limit-in-ngnix-in-aws-server-2820c491e9a4

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM