title: Multiple File Upload using @Context HttpServletRequest with @FormDataParam in jersey
body: <p>I have created a jersey restful web service where I <strong>managed</strong> to upload <strong>multiple number of files</strong> using <code>@Context HttpServletRequest request</code> as method signature which work nicely.<br>
  Thing is, to fetch other form fields I need to repetitively check with <code>.isFormField();</code> method with relative <code>.getName();</code> for file or <code>.getFieldName();</code>, and <code>.getString();</code> method to check whether required fields are present or not <strong>every time the web service is called</strong> which I think little lengthy and expensive process if there are several other fields.  </p>
  
  <p>Easier approach was to use <code>@FormDataParam</code> where webservice used to exposed with parameter which client need to pass but <strong>problem</strong> is I am not able to upload more than one file at one go.  </p>
  
  <p>Since Its also not possible to use <code>request.getParameter("field1");</code> to get other form fields if media type or enctype is <code>multipart/form-data</code>.  </p>
  
  <p>Whenever I tried to combine both <code>@FormDataParam</code> and <code>@Context HttpServletRequest request</code> together, it throws exception:<br>
  <code>org.apache.tomcat.util.http.fileupload.FileUploadException: Stream closed</code><br>
  while parsing the <strong>request</strong> with <code>.parseRequest(request);</code> method of <code>ServletFileUpload</code> class.  </p>
  
  <p>Kindly suggest some good approach How can I achieve multiple file upload with getting required form fields as easy as <code>@FormDataParam</code> in jersey.</p>
  
  <p><strong>approach for multiple file upload:</strong>  </p>
  
  <pre><code>@POST
  @Consumes(MediaType.MULTIPART_FORM_DATA)
  @Produces(MediaType.APPLICATION_JSON)
  @Path("/multipleFiles")
  public String restDemo(@Context HttpServletRequest request) 
  {
    //...code goes here
  }
  </code></pre>
  
  <p><strong>My form:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/hKAOW.png" alt="enter image description here"></p>
  
  <p><strong>output:(after parsing request)</strong>  </p>
  
  <blockquote>
    <p>field1 > abc<br>
    field2 > xyz<br>
    Chrysanthemum.jpg Size: 879394<br>
    Desert.jpg Size: 845941<br>
    Hydrangeas.jpg Size: 595284<br>
    Jellyfish.jpg
    Size: 775702</p>
  </blockquote>