gpt4 book ai didi

java - 在 Spring Boot 2.2.5 应用程序中上传文件时出现 MalformedStreamException

转载 作者:行者123 更新时间:2023-12-01 17:57:34 24 4
gpt4 key购买 nike

在我的应用程序中将 Spring Boot 从 2.2.4 升级到 2.2.5 后,使用 multipart/form-data 表单上传文件时出现以下异常:

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly] with root cause

org.apache.commons.fileupload.MultipartStream$MalformedStreamException: Stream ended unexpectedly
at org.apache.commons.fileupload.MultipartStream$ItemInputStream.makeAvailable(MultipartStream.java:1033)
at org.apache.commons.fileupload.MultipartStream$ItemInputStream.read(MultipartStream.java:931)
at java.io.InputStream.read(InputStream.java:101)
at org.apache.commons.fileupload.util.Streams.copy(Streams.java:98)
at org.apache.commons.fileupload.util.Streams.copy(Streams.java:68)
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:346)
at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:113)
at org.springframework.web.multipart.commons.CommonsMultipartResolver.parseRequest(CommonsMultipartResolver.java:159)
at org.springframework.web.multipart.commons.CommonsMultipartResolver.resolveMultipart(CommonsMultipartResolver.java:143)
at org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:1178)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1012)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:665)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:750)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:320)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:126)
...

表格如下所示:

<form id="addPhotosForm" method="post" action="/images/add" enctype="multipart/form-data">
<div class="row">
<div class="col-sm-4">
<div class="input-group">
<input type="file" name="images" multiple>
</div>
</div>
<div class="col-sm-6 pull-left">
<input name="submit" type="submit" value="Save">
</div>
</div>
</form>

Controller 看起来像这样:

@RequestMapping(value = "/images/add")
public String addPhoto(@RequestParam(value = "images", required = false) MultipartFile[] multipartImages) {
//...
}

最佳答案

将 Spring Boot 更新到版本 2.2.6 后工作正常。

关于java - 在 Spring Boot 2.2.5 应用程序中上传文件时出现 MalformedStreamException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60688842/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com