Spring boot文件上传blocked a frame with origin "http://xxx" from accessing a cross-origin frame.

spring boot 上传文件,页面弹出提示:blocked a frame with origin “http://localhost:8080” from accessing a cross-origin frame.

在上传文件的过程中,前端报了这个错误,这个错误咋一看还还以为是AJAX提交数据跨域的问题,实则和跨域没有一毛线关系,这个提示是DOMException报出的提示,具体错误状态值为:

{
    code :18,
    message:"Blocked a frame with origin "http://localhost:8080" from accessing a cross-origin frame."
    name:"SecurityError"
    stack:"Error: "Error: Blocked a frame with origin "http://localhost:8081" from accessing a cross-origin frame.↵    at HTMLIFrameElement.uploadCallback (http://localhost:8080/lib/ajaxfileupload.js:78:60)↵    at HTMLIFrameElement.dispatch (http://localhost:8080/tmp/system/article/js/jquery-1.9.1.min.js:3:28337)↵    at HTMLIFrameElement.v.handle (http://localhost:8080/tmp/system/article/js/jquery-1.9.1.min.js:3:25042)"
}

查看DOMException文档,SecurityError的说明是The operation is insecure. (Legacy code value: 18 and legacy constant name: SECURITY_ERR)。大致意思就是操作不安全,具体是什么操作不安全得去看后端。

去后端一看错误一目了然:

Caused by: java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (5537806) exceeds the configured maximum (4194304)

request异常,上传的文件超过了最大值2047512,也就是2M,这个是默认的(具体是哪里给的默认值没有深究)上传大小限制。so,那去查下spring boot上传文件大小限制的配置属性,然后在application.properties添加就可以了。

需要注意的是spring boot各个版本间的这个配置有些改动。

各版本文件大小限制如下:

  • 1.0
spring.servlet.multipart.max-file-size=1MB 
spring.servlet.multipart.max-request-size=10MB 
  • 1.2~1.3
multipart.max-file-size=1Mb 
multipart.max-request-size=10Mb 
  • 1.4~1.5
spring.http.multipart.max-file-size=1Mb 
spring.http.multipart.max-request-size=10Mb 

恕我眼拙,没有找到1.1版本上传文件大小限制的配置。

欢迎关注我的个人公众号:逍遥的心。主推程序员写的生活类文章,有兴趣的朋友可以共同探讨下:Spring boot文件上传blocked a frame with origin

你可能感兴趣的:(springboot,Exception,java)