title: File Upload with Description in Restlet
body: <p>I need to <strong>upload a file</strong> with some additional data using <strong>restlet</strong>. So i create a sample html page like below.</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
      &lt;h1&gt;*****Upload File with RESTFul WebService*****&lt;/h1&gt;
      &lt;form action="http://localhost:8080/test/api/streams/sample.json" method="post" enctype="multipart/form-data"&gt;
  
  
          &lt;fieldset&gt;
              &lt;legend&gt;Upload File&lt;/legend&gt;
  
              &lt;input type="file" name="fileToUpload"/&gt;&lt;br /&gt;  
              &lt;br /&gt;&lt;br /&gt;
              Party ID&lt;input type="text" name="mybody"  /&gt;&lt;br /&gt;
  
  
              &lt;input type="submit" name="Upload" id="Upload" value="Upload" /&gt;
          &lt;/fieldset&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p></p>
  
  <p>I need to read the value from <strong>input field</strong> along with the file data.Now it is possible to read the file content.how can i get value from that input box in the same api call.</p>
  
  <pre><code>@Post
  public Representation accept(Representation entity) throws Exception {
  Representation result = null;
  
  
  if (entity != null) {
    if (MediaType.MULTIPART_FORM_DATA.equals(entity.getMediaType(), true)) {
      // 1/ Create a factory for disk-based file items
      DiskFileItemFactory factory = new DiskFileItemFactory();
      factory.setSizeThreshold(1000240);
  
      // 2/ Create a new file upload handler based on the Restlet
      // FileUpload extension that will parse Restlet requests and
      // generates FileItems.
      RestletFileUpload upload = new RestletFileUpload(factory);
  
      // 3/ Request is parsed by the handler which generates a
      // list of FileItems
      FileItemIterator fileIterator = upload.getItemIterator(entity);
  
      // Process only the uploaded item called "fileToUpload"
      // and return back
      boolean found = false;
      while (fileIterator.hasNext() &amp;&amp; !found) {
        FileItemStream fi = fileIterator.next();
        Extractor extractor = new Extractor(getContext());
  
        if (fi.getFieldName().equals("fileToUpload")) {
          found = true;
          // consume the stream immediately, otherwise the stream
          // will be closed.
          StringBuilder sb = new StringBuilder("media type: ");
          sb.append(fi.getContentType()).append("\n");
          sb.append("file name : ");
          sb.append(fi.getName()).append("\n");
          BufferedReader br = new BufferedReader(new InputStreamReader(fi.openStream()));
          String line = null;
          while ((line = br.readLine()) != null) {
            sb.append(line);
          }
          sb.append("\n");
          result = new StringRepresentation(sb.toString(), MediaType.TEXT_PLAIN);
        }
      }
    } else {
      setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
    }
    System.out.println("result==" + result);
  }
  
  
  return result;
  </code></pre>
  
  <p>}</p>