一个新的奇葩问题:前端报跨域出错,原因却是后台上传的文件超过了Tomcat限制。
前端报错
Access to XMLHttpRequest at 'http://localhost:8120/admin/oss/file/upload?module=avatar' from origin 'http://localhost:9528' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
后端日志
org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes.
所以啊,这根本不是跨域的问题,Tomcat默认上传的文件大小就是1MB,你上传的文件超过而已。
你可以在前端配置一下文件大小限制,
例如
或者在后端设置上传文件大小限制
以SpringBoot为例
在application.yml中添加配置
spring:
servlet:
multipart:
单个文件上传大小
max-request-size: 50MB
一次请求的多个文件大小
max-file-size: 50MB
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有