title: Jersey 2.x Multipart/form-data server returns 400 Bad Request and MessageBodyWriterNotFoundException
body: <p>When I run my Multipart/form-data uploading feature in jersey 2.26, it returns 400-Bad request. I triedno many ways but no use</p>
  <p>when uploading without file, it shows the response message. when I use client &quot;MessageBodyWriterNotFoundException&quot; showed.</p>
  <p>Upload.java</p>
  <pre><code>@Path(&quot;/upload&quot;)
  public class UploadFileDemo {
      
      @POST
      @Consumes(MediaType.MULTIPART_FORM_DATA)
      @Produces(MediaType.TEXT_PLAIN)
      public Response uploadFile(@FormDataParam(&quot;file&quot;) FileInputStream fileInputStream,
                                  @FormDataParam(&quot;file&quot;) FormDataContentDisposition fileInfo) {
          System.out.println(fileInfo.getFileName()+&quot;-&quot;+fileInfo.getSize());
          String path= &quot;D://&quot;+fileInfo.getFileName();
          int read=0;
          byte[] bytes = new byte[1024];
          try {
              OutputStream out = new FileOutputStream(new File(path));
              while((read = fileInputStream.read(bytes))!=-1) {
                  out.write(bytes, 0, read);
              }
              out.flush();
              out.close();    
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
          return Response.ok(&quot;Data uploaded successfully&quot;).build();
      }
  
  }
  </code></pre>
  <p>web.xml</p>
  <pre><code>&lt;servlet&gt;
          &lt;servlet-name&gt;Jersey Web Application&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.glassfish.jersey.servlet.ServletContainer&lt;/servlet-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;jersey.config.server.provider.packages&lt;/param-name&gt;
              &lt;param-value&gt;com.packages.resource&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;jersey.config.server.provider.classnames&lt;/param-name&gt;
              &lt;param-value&gt;org.glassfish.jersey.filter.LoggingFilter;
              org.glassfish.jersey.media.multipart.MultiPartFeature&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Jersey Web Application&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/webapi/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  </code></pre>
  <p><strong>FYI- No exception showed</strong></p>
  <pre><code>My logging filter log
  Aug 25, 2020 12:53:29 PM org.glassfish.jersey.filter.LoggingFilter log
  INFO: 1 * Server has received a request on thread http-nio-9090-exec-8
  1 &gt; POST http://localhost:9090/rest-new-version/webapi/upload/file
  1 &gt; accept: */*
  1 &gt; accept-encoding: gzip, deflate, br
  1 &gt; connection: keep-alive
  1 &gt; content-length: 240
  1 &gt; content-type: multipart/form-data; boundary=--------------------------247816562830114154909314
  1 &gt; host: localhost:9090
  1 &gt; postman-token: 91bec8ef-5857-4604-a512-6dc97d5e22c6
  1 &gt; user-agent: PostmanRuntime/7.26.3
  
  Aug 25, 2020 12:53:30 PM org.glassfish.jersey.filter.LoggingFilter log
  INFO: 1 * Server responded with a response on thread http-nio-9090-exec-8
  1 &lt; 400
  </code></pre>
  <p>please help me to get through this :)</p>