Youssef Youssef - 2 months ago 52
Java Question

Upload file stop with Unexpected EOF read on the socket Exception

Sometime when I try to upload a file on my remote vps i get this exception (the upload proccess stop in 60%)

06-Jan-2016 11:59:36.801 SEVERE [http-nio-54000-exec-9] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [mvc-dispatcher] in context with path [] threw exception [Request processing failed;
nested exception is org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request;
nested exception is org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. Unexpected EOF read on the socket]
with root cause Unexpected EOF read on the socket

and in
Google Chrome
the connextion is lost like the server is down, i get

i upload file like this in spring mvc

public void save_file(MultipartFile upfile , String path){

try {

File fichier = new File( path ) ;
byte[] bytes = upfile.getBytes();
BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream( fichier ));
System.out.println( "You successfully uploaded " + upfile.getOriginalFilename() + "!" );

} catch (Exception e) {
System.out.println( "You failed to upload " + upfile.getOriginalFilename() + " => " + e.getMessage() ); ;


my controller :

@RequestMapping(value = "/administration/upload", method = RequestMethod.POST)
public String Upload_AO_journal(
@ModelAttribute UploadForm uploadForm,
Model map , HttpServletRequest request, HttpSession session ) throws ParseException, UnsupportedEncodingException {

my bean

public class UploadForm {

public MultipartFile scan;

So how can solve this problem ?


Have you tried stream?

Jsp code:

<form method="POST" onsubmit="" ACTION="url?${_csrf.parameterName}=${_csrf.token}" ENCTYPE="multipart/form-data">


        value = "url", method = RequestMethod.POST
public void uploadFile(
        @RequestParam("file") MultipartFile file
) throws IOException {

 InputStream input = upfile.getInputStream();
 Path path = Paths.get(path);//check path
 OutputStream output = Files.newOutputStream(path);
 IOUtils.copy(in, out); // or you can create IOUtils.copy


All that worked for me with spring 4.0 and spring security.

Secondly, you should check if the http connection is timeout. Chrome does not support that configuration. So you can use firefox and follow here