title: Parsing File upload in Spring
body: <p>I want to parse request body which accepts a file as multipart/form-data. Currently, when I try to print the inputStream as string, I get like below:</p>
  <pre><code>----------------------------559363225496099939024171
  Content-Disposition: form-data; 
  name=&quot;file&quot;; 
  filename=&quot;upload.txt&quot;
  Content-Type: text/plain
  {  
      &quot;documents&quot;: [    
          {      
              &quot;id&quot;: &quot;1&quot;,
              &quot;text&quot;: &quot;abc&quot;    
          }  
       ]
  }
  ----------------------------559363225496099939024171
  </code></pre>
  <p>Below is my <strong>controller.java</strong></p>
  <pre><code>    @POST
      @Path(&quot;/modelInfo&quot;)
      @Produces({ &quot;application/json&quot; })
      @Consumes(MediaType.MULTIPART_FORM_DATA)
      public Response getModel(InputStream file) throws IOException {
  
          InputStreamReader isReader = new InputStreamReader(file, StandardCharsets.UTF_8);
          //Creating a BufferedReader object
          BufferedReader reader = new BufferedReader(isReader);
          StringBuffer sb = new StringBuffer();
          String str;
          while ((str = reader.readLine()) != null) {
              sb.append(str);
          }
     
          return Response.status(Response.Status.OK).entity(sb.toString()).build();
      }
  </code></pre>
  <p><strong>upload.txt</strong></p>
  <pre><code>{
    &quot;documents&quot;: [
      {
        &quot;id&quot;: &quot;1&quot;,
        &quot;text&quot;: &quot;abc&quot;
      }
    ]
  }
  </code></pre>
  <p>So basically, I am sending <code>sb.toString()</code> back to response body.</p>
  <p>My question is, how to extract only the content data from the above response I am getting?</p>
  <p>I tried using <code>MultipartFile</code>, still no luck</p>