前端小程序调用服务端的文件上传接口,有一台安卓机上传一直报错:
报错日志:
- {"statusCode": 500, "header": {"Date": "Wed, 29 Mar 2023 06:45:39 GMT", "Content-Language": "en", "Server": "nginx", "Content-Type": "text/html;charset=utf-8", "Transfer-Encoding": "chunked", "Connection": "keep-alive", "protocol": "http/1.1"}, "data": "<!doctype html><html lang="en"><head><title>HTTP Status 500 – Internal Server Error</title><style type="text/css">h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 500 – Internal Server Error</h1><hr class="line" /><p><b>Type</b> Exception Report</p ><p><b>Message</b> Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found</p ><p><b>Description</b> The server encountered an unexpected condition that prevented it from fulfilling the request.</p ><p><b>Exception</b></p ><pre>org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found\n\torg.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1013)\n\torg.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)\n\tjavax.servlet.http.HttpServlet.service(HttpServlet.java:661)\n\torg.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)\n\tjavax.servlet.http.HttpServlet.service(HttpServlet.java:742)\n\torg.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)\n\torg.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)\n\torg.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)\n\torg.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)\n\torg.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)\n\torg.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:387)\n\torg.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)\n\torg.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)\n\torg.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:357)\n\torg.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:270)\n\torg.springframework.mobile.device.site.SitePreferenceRequestFilter.doFilterInternal(SitePreferenceRequestFilter.java:56)\n\torg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109)\n\torg.springframework.mobile.device.DeviceResolverRequestFilter.doFilterInternal(DeviceResolverRequestFilter.java:60)\n\torg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109)\n\torg.springframework.web.filter.ShallowEtagHeaderFilter.doFilterInternal(ShallowEtagHeaderFilter.java:108)\n\torg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109)\n\torg.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)\n\torg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109)\n</pre><p><b>Root Cause</b></p ><pre>org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found\n\torg.springframework.web.multipart.commons.CommonsMultipartResolver.parseRequest(CommonsMultipartResolver.java:168)\n\torg.springframework.web.multipart.commons.CommonsMultipartResolver.resolveMultipart(CommonsMultipartResolver.java:142)\n\torg.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:1176)\n\torg.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1011)\n\torg.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)\n\torg.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)\n\torg.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)\n\tjavax.servlet.http.HttpServlet.service(HttpServlet.java:661)\n\torg.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)\n\tjavax.servlet.http.HttpServlet.service(HttpServlet.java:742)\n\torg.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)\n\torg.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)\n\torg.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)\n\torg.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)\n\torg.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)\n\torg.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:387)\n\torg.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)\n\torg.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)\n\torg.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:357)\n\torg.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:270)\n\torg.springframework.mobile.device.site.SitePreferenceRequestFilter.doFilterInternal(SitePreferenceRequestFilter.java:56)\n\torg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109)\n\torg.springframework.mobile.device.DeviceResolverRequestFilter.doFilterInternal(DeviceResolverRequestFilter.java:60)\n\torg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109)\n\torg.springframework.web.filter.ShallowEtagHeaderFilter.doFilterInternal(ShallowEtagHeaderFilter.java:108)\n\torg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109)\n\torg.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)\n\torg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109)\n</pre><p><b>Root Cause</b></p ><pre>org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found\n\torg.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:990)\n\torg.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:310)\n\torg.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:334)\n\torg.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:115)\n\torg.springframework.web.multipart.commons.CommonsMultipartResolver.parseRequest(CommonsMultipartResolver.java:158)\n\torg.springframework.web.multipart.commons.CommonsMultipartResolver.resolveMultipart(CommonsMultipartResolver.java:142)\n\torg.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:1176)\n\torg.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1011)\n\torg.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)\n\torg.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)\n\torg.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)\n\tjavax.servlet.http.HttpServlet.service(HttpServlet.java:661)\n\torg.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)\n\tjavax.servlet.http.HttpServlet.service(HttpServlet.java:742)\n\torg.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)\n\torg.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)\n\torg.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)\n\torg.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)\n\torg.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)\n\torg.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:387)\n\torg.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)\n\torg.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)\n\torg.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:357)\n\torg.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:270)\n\torg.springframework.mobile.device.site.SitePreferenceRequestFilter.doFilterInternal(SitePreferenceRequestFilter.java:56)\n\torg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109)\n\torg.springframework.mobile.device.DeviceResolverRequestFilter.doFilterInternal(DeviceResolverRequestFilter.java:60)\n\torg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109)\n\torg.springframework.web.filter.ShallowEtagHeaderFilter.doFilterInternal(ShallowEtagHeaderFilter.java:108)\n\torg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109)\n\torg.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)\n\torg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109)\n</pre><p><b>Note</b> The full stack trace of the root cause is available in the server logs.</p ><hr class="line" /><h3>Apache Tomcat/8.5.37</h3></body></html>", "cookies": [], "errMsg": "uploadFile:ok"} 123432123432 success
具体报错是这段:
Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found
原因:
前端在上传照片时,headers写死了 content-type="multipart/form-data",导致浏览器无法在请求头加上boundary标识,产生冲突
解决方案:
前端headers设置 contentType:false或者注掉contentType,这样上传图片request请求会自动添加这个请求参数的格式和boundary标识,就不会报错了
文章来源:https://www.toymoban.com/news/detail-777224.html
本文参考FileUploadException: the request was rejected because no multipart boundary was found_shangqing.liu的博客-CSDN博客文章来源地址https://www.toymoban.com/news/detail-777224.html
到了这里,关于fileupload.FileUploadException: the request was rejected because no multipart boundary was found的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!