Я использую Spring Boot 2.0.0 для загрузки файлов на сервер и получаю эту ошибку:
Servlet.service () для сервлета [dispatcherServlet] в контексте с путем [/ project] выдало исключение [Ошибка обработки запроса;вложенным исключением является org.springframework.web.multipart.MultipartException: не удалось проанализировать многочастный запрос сервлета;вложенное исключение: java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadException: непредвиденное чтение EOF в сокете] с основной причиной
java.io.EOFException: непредвиденное чтение EOF всокет в org.apache.coyote.http11.Http11InputBuffer.fill (Http11InputBuffer.java:722) ~ [tomcat-embed-core-8.5.28.jar: 8.5.28] в org.apache.coyote.http11.Http11InputBufferac$ 300 (Http11InputBuffer.java:40) ~ [tomcat-embed-core-8.5.28.jar: 8.5.28] в org.apache.coyote.http11.Http11InputBuffer $ SocketInputBuffer.doRead (Http11InputBuffer.java t10cat)-embed-core-8.5.28.jar: 8.5.28] в org.apache.coyote.http11.filters.IdentityInputFilter.doRead (IdentityInputFilter.java:140) ~ [tomcat-embed-core-8.5.28.jar:8.5.28] в org.apache.coyote.http11.Http11InputBuffer.doRead (Http11InputBuffer.java:261) ~ [tomcat-embed-core-8.5.28.jar: 8.5.28] в org.apache.coyote.Request. doRead (Request.java:581) ~ [tomcat-embed-core-8.5.28.jar: 8.5.28] в org.apache.catalina.connector.InputBuffer.realReadBytes (InputBuffer.java:326) ~ [tomcat-embed-core-8.5.28.jar: 8.5.28] в org.apache.catalina.connector.InputBuffer.checkByteBufferEof (InputBuffer.java:642) ~ [tomcat-embed-core-8.5.28.jar: 8.5.28] at org.apache.catalina.connector.InputBuffer.read (InputBuffer.java:349) ~ [tomcat-embed-core-8.5.28.jar: 8.5.28]в org.apache.catalina.connector.CoyoteInputStream.read (CoyoteInputStream.java:183) ~ [tomcat-embed-core-8.5.28.jar: 8.5.28] в java.io.FilterInputStream.read (FilterInputStream.java:133) ~ [na: 1.8.0_161] at org.apache.tomcat.util.http.fileupload.util.LimitedInputStream.read (LimitedInputStream.java:132) ~ [tomcat-embed-core-8.5.28.jar: 8.5.28] в org.apache.tomcat.util.http.fileupload.MultipartStream $ ItemInputStream.makeAvailable (MultipartStream.java:977) ~ [tomcat-embed-core-8.5.28.jar: 8.5.28] в org.apache.tomcat.util.http.fileupload.MultipartStream $ ItemInputStream.read (MultipartStream.java:881) ~ [tomcat-embed-core-8.5.28.jar: 8.5.28] в java.io.InputStream.read (InputStream. java: 101) ~ [na: 1.8.0_161] в org.apache.tomcat.util.http.fileupload.util.Streams.copy (Streams.java:98) ~ [tomcat-embed-core-8.5.28.jar: 8.5.28] в org.apache. tomcat.util.http.fileupload.util.Streams.copy (Streams.java:68) ~ [tomcat-embed-core-8.5.28.jar: 8.5.28] в org.apache.tomcat.util.http.fileupload.MultipartStream.readBodyData (MultipartStream.java:572) ~ [tomcat-embed-core-8.5.28.jar: 8.5.28] в org.apache.tomcat.util.http.fileupload.MultipartStream.discardBodyData (MultipartStream.java:596) ~ [tomcat-embed-core-8.5.28.jar: 8.5.28] на org.apache.tomcat.util.http.fileupload.MultipartStream.skipPreamble (MultipartStream.java:614) ~ [tomcat-embed-core-8.5.28.jar: 8.5.28] at org.apache.tomcat.util.http.fileupload.FileUploadBase $ FileItemIteratorImpl.findNextItem (FileUploadBase.java:865) ~ [tomcat-embed-core-8.5.28.jar:8.5.28] в org.apache.tomcat.util.http.fileupload.FileUploadBase $ FileItemIteratorImpl. (FileUploadBase.java:845) ~ [tomcat-embed-core-8.5.28.jar: 8.5.28] в org.apache.tomcat.util.http.fileupload.FileUploadBase.getItemIterator (FileUploadBase.java:256) ~ [tomcat-embed-core-8.5.28.jar: 8.5.28] в org.apache.tomcat.util.http.fileupload.FileUploadBase.parseRequest (FileUploadBase.java:280) ~ [tomcat-embed-core-8.5.28.jar: 8.5.28] в org.apache.catalina.connector.Request.parseParts (Request.java:2869) ~ [tomcat-embed-core-8.5.28. jar: 8.5.28] at org.apache.catalina.connector.Request.parseParameters (Request.java:3216)~ [tomcat-embed-core-8.5.28.jar: 8.5.28] в org.apache.catalina.connector.Request.getParameter (Request.java:1137) ~ [tomcat-embed-core-8.5.28.jar: 8.5.28] в org.apache.catalina.connector.RequestFacade.getParameter (RequestFacade.java:381) ~ [tomcat-embed-core-8.5.28.jar: 8.5.28] в org.springframework.web.filter.HiddenHttpMethodFilter. ~ [spring-web-5.0.4.RELEASE.jar: 5.0.4.RELEASE] на org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:193) ~ [tomcat-embed-core-8.5.28.jar: 8.5.28] at org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:166) ~ [tomcat-embed-core-8.5.28.jar: 8.5.28] на org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal (CharacterEncodingFilter.java:200) ~ [spring-web-5.0.4.RELEASE.jar: 5.0.4.RELEASE] в организации.springframework.web.filter.OncePerRequestFilter.doFilter (OncePerRequestFilter.java:107) ~ [spring-web-5.0.4.RELEASE.jar: 5.0.4.RELEASE] в org.apache.catalina.core.ApplicationFilterDohain. ApplicationFilterChain.java:193) ~ [tomcat-embed-core-8.5.28.jar: 8.5.28] в org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:166) ~ [tomcat-embed-core-8.5.28.jar: 8.5.28] в org.apache.catalina.core.StandardWrapperValve.invoke (StandardWrapperValve.java:199) ~ [tomcat-embed-core-8.5.28.jar: 8.5.28] в org.apache.catalina.core.. : 496) [tomcat-embed-core-8.5.28.jar: 8.5.28] в org.apache.catalina.core.StandardHostValve.invoke (StandardHostValve.java:140) [tomcat-embed-core-8.5.28. jar: 8.5.28] at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:81) [tomcat-embed-core-8.5.28.jar: 8.5.28] в org.apache.catalina.core.StandardEngineValve.invoke (StandardEngineValve.java:87) [tomcat-embed-core-8.5.28.jar: 8.5.28] в организации.apache.catalina.connector.CoyoteAdapter.service (CoyoteAdapter.java:342) [tomcat-embed-core-8.5.28.jar: 8.5.28] в org.apache.coyote.http11.Http11Processor.service (Http11Processor.java: 803) [tomcat-embed-core-8.5.28.jar: 8.5.28] в org.apache.coyote.AbstractProcessorLight.process (AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.28.jar:8.5.28] в org.apache.coyote.AbstractProtocol $ ConnectionHandler.process (AbstractProtocol.java:790) [tomcat-embed-core-8.5.28.jar: 8.5.28] в org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun (NioEndpoint.java:1459) [tomcat-embed-core-8.5.28.jar: 8.5.28] в org.apache.tomcat.util.net.SocketProcessorBase.run (SocketProcessorBase.java:49) [tomcat-embed-core-8.5.28.jar: 8.5.28] в java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149) [na: 1.8.0_161] в java.util.concurrent.ThrereadPoolExecutor $ Worker.run (ThreadPoolExecutor.java:624) [na: 1.8.0_161] в org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run (TaskThread.java:61) [tomcat-embed-core-8.5.28.jar: 8.5.28] at java.lang.Thread.run (Thread.java:748) [na: 1.8.0_161]
Это мой интерфейс:
<form class="form" enctype="multipart/form-data" >
<div class="book__row form__group ">
<select id="dropdown-category" name="options" class="form__input" required>
<option value="0">Wählen Sie eine Kategorie aus</option>
</select>
</div>
<div class="book__row form__group ">
<select id="dropdown-subcategory" name="options" class="form__input" required>
</select>
</div>
<div class="form__group">
<input type="text" class="form__input form__input--blue-border" placeholder="NAME" id="filename" required>
<label for="title" class="form__label">NAME</label>
</div>
<div class="form__group">
<textarea id="description" class="form__input form__input--blue-border " rows="4" cols="50" name="comment" form="usrform"
required> BESCHREIBUNG
</textarea>
</div>
<div class="form__group input-file-container">
<input class="input-file" id="fileStream" type="file" required>
<label tabindex="0" for="my-file" class="input-file-trigger">Datei hochladen</label>
<p class="file-return"></p>
</div>
<div class=" form__group input-file-container" id="addBinaryDoc">
<input class="input-file" type="submit">
<label tabindex="0" for="form-btn" class="input-file-trigger">Dokument hinzufügen</label>
<p class="file-return"></p>
</div>
</form>
JS
var data = new FormData();
data.append("fileStream", file);
data.append("metadata", new Blob([JSON.stringify(doc)], { type: "application/json" }));
return $.ajax({
type: "POST",
url: '/my/path',
data: data,
enctype: 'multipart/form-data',
cache: false,
contentType: false,
processData: false
});
BACKEND: мой контроллер:
@RequestMapping(value = "save",headers = "content-type=multipart/*", method = { RequestMethod.POST
}, consumes = "multipart/form-data")
@ResponseBody
public void saveDocument(@RequestParam("fileStream") MultipartFile multipartFile,
@RequestPart(name = "metadata", required = false) @Valid Document uploadedDocument)
Я также добавил многочастный преобразователь
@Bean
public MultipartResolver multipartResolver() {
MultipartResolver resolver = new StandardServletMultipartResolver();
return resolver;
}
@Bean
MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
factory.setMaxFileSize("5120MB");
factory.setMaxRequestSize("5120MB");
return factory.createMultipartConfig();
}
application.properties
:
spring.servlet.multipart.max-file-size=5MB
spring.servlet.multipart.max-request-size=10MB
spring.servlet.multipart.enabled=true
Tomcat context.xml
<Context allowCasualMultipartParsing="true" path="/">
<Resources cachingAllowed="true" cacheMaxSize="100000" />
</context>
Tomcat web.xml
<session-config>
<session-timeout>60</session-timeout>
</session-config>
Tomcat servlet.xml
<Connector port="1050"
maxThreads="400" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionUploadTimeout="36000000" connectionTimeout="60000" disableUploadTimeout="false"
/>
В чем может быть причина этой ошибки?