java – multiple uploads was failed using dio in flutter(Spring Boot, Flutter)

when i usign postman, it was successful all of time. but flutter using dio was not working multiple uploading.
At the first time uploadig was successful, but second time upload was failed.

Spring boot Exception:

java.io.EOFException: null
        at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.fillReadBuffer(NioEndpoint.java:1306) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.read(NioEndpoint.java:1218) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.coyote.http11.Http11InputBuffer.fill(Http11InputBuffer.java:805) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.coyote.http11.Http11InputBuffer.access$400(Http11InputBuffer.java:42) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.coyote.http11.Http11InputBuffer$SocketInputBuffer.doRead(Http11InputBuffer.java:1185) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.coyote.http11.filters.IdentityInputFilter.doRead(IdentityInputFilter.java:101) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.coyote.http11.Http11InputBuffer.doRead(Http11InputBuffer.java:249) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.coyote.Request.doRead(Request.java:640) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.catalina.connector.InputBuffer.realReadBytes(InputBuffer.java:316) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.catalina.connector.InputBuffer.checkByteBufferEof(InputBuffer.java:599) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.catalina.connector.InputBuffer.read(InputBuffer.java:339) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.catalina.connector.CoyoteInputStream.read(CoyoteInputStream.java:132) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at java.base/java.io.FilterInputStream.read(FilterInputStream.java:132) ~[na:na]
        at org.apache.tomcat.util.http.fileupload.util.LimitedInputStream.read(LimitedInputStream.java:132) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.tomcat.util.http.fileupload.MultipartStream$ItemInputStream.makeAvailable(MultipartStream.java:975) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.tomcat.util.http.fileupload.MultipartStream$ItemInputStream.read(MultipartStream.java:879) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at java.base/java.io.InputStream.read(InputStream.java:218) ~[na:na]
        at org.apache.tomcat.util.http.fileupload.util.Streams.copy(Streams.java:97) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.tomcat.util.http.fileupload.util.Streams.copy(Streams.java:68) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.tomcat.util.http.fileupload.MultipartStream.readBodyData(MultipartStream.java:572) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.tomcat.util.http.fileupload.MultipartStream.discardBodyData(MultipartStream.java:596) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.tomcat.util.http.fileupload.MultipartStream.skipPreamble(MultipartStream.java:614) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.tomcat.util.http.fileupload.impl.FileItemIteratorImpl.findNextItem(FileItemIteratorImpl.java:228) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.tomcat.util.http.fileupload.impl.FileItemIteratorImpl.<init>(FileItemIteratorImpl.java:142) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.tomcat.util.http.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:252) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.tomcat.util.http.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:276) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.catalina.connector.Request.parseParts(Request.java:2932) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.catalina.connector.Request.getParts(Request.java:2834) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.catalina.connector.RequestFacade.getParts(RequestFacade.java:1098) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.java:95) ~[spring-web-5.3.16.jar!/:5.3.16]
        at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.<init>(StandardMultipartHttpServletRequest.java:88) ~[spring-web-5.3.16.jar!/:5.3.16]
        at org.springframework.web.multipart.support.StandardServletMultipartResolver.resolveMultipart(StandardServletMultipartResolver.java:122) ~[spring-web-5.3.16.jar!/:5.3.16]
        at org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:1205) ~[spring-webmvc-5.3.16.jar!/:5.3.16]
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1039) ~[spring-webmvc-5.3.16.jar!/:5.3.16]
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) ~[spring-webmvc-5.3.16.jar!/:5.3.16]
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.16.jar!/:5.3.16]
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.3.16.jar!/:5.3.16]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:681) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.3.16.jar!/:5.3.16]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:764) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.58.jar!/:na]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.3.16.jar!/:5.3.16]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.16.jar!/:5.3.16]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.3.16.jar!/:5.3.16]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.16.jar!/:5.3.16]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:96) ~[spring-boot-actuator-2.6.4.jar!/:2.6.4]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.16.jar!/:5.3.16]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.3.16.jar!/:5.3.16]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.16.jar!/:5.3.16]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:359) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:889) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1735) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.58.jar!/:na]
        at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]

it caused by disconnecting from client or Timeout

I added spring servlet option(multipart max-file-size, max-request-size, templocation), but didn’t work this problem.(i added this options another problem)

RestController Code is

public ResponseEntity<RestResponseW> UploadVideo(@RequestParam(name="video") List<MultipartFile> video,
                                      @RequestParam(name="thumbnail") MultipartFile thumbnail,
                                      @RequestAttribute long userId, @RequestParam(name="modelName") String modelName) throws Exception {
        return new ResponseEntity<>(row.Upload(userId, video, thumbnail, modelName), HttpStatus.OK);
    }

Flutter Code is

_save() async {
    SmartDialog.showLoading(widget: const CustomLoading(type: 1));
    for (int i = 0; i < vids.length; i++) {
      String vidPath = vids[i].path;
      MultipartFile multipartFile = await MultipartFile.fromFile(
        vidPath,
        contentType: MediaType('mp4', 'MOV'),
        filename: vidPath,
      );
      if (galleryFlag == true && cameraFlag == false) {
        listGallery.add(multipartFile);
      }
      if (galleryFlag == false && cameraFlag == true) {
        listCamera.add(multipartFile);
      }
    }
    MultipartFile multipartFile = await MultipartFile.fromFile(
      thumbnails[0],
      contentType: MediaType('png', 'jpg'),
      filename: 'thumbnail',
    );
    FormData formData = FormData.fromMap(
      {
        // 'video[]': _list,
        // 'user_col': value,
        // 'thumbnail': multipartFile,
        'video': galleryFlag ? listGallery : listCamera,
        'thumbnail': multipartFile,
        'scribble': '',
        'modelName': galleryFlag ? objectString : objectStringCam,
      },
    );
    try {
      var response = await dio.post(
        '${Constants.backApiURL}/app/row/upload',
        data: formData,
        // cancelToken: cToken,
        options: Options(
          receiveTimeout: 60 * 1000,
          headers: {
            "Authorization": "Bearer ${Constants.accessToken}",
          },
          responseType: ResponseType.json,
        ),
      );
      if (response.statusCode == 200) {
        print(response.data);
        print('success');
        if (mounted) {
          setState(() {
            responseB = '1';
          });
        }
        var a = response.data;
        SmartDialog.dismiss();
        SmartDialog.showToast(
          '',
          time: const Duration(
            seconds: 1,
          ),
          widget: const CustomToastUploaded(
            '업로드가 완료되었습니다.',
          ),
        );
        dio.clear();
        return response;
      } else {
        return response;
      }
    } on Exception catch (e) {
      Exception(e);
    } finally {
      dio.close();
    }
    return false;
  }

What should i do?
(Inv : Spring Boot 2.5.4, OpenJDK17,Embedded-Tomcat 9.0.58, Flutter 2, dio)

Leave a Comment