title: File Upload through rest and html as client
body: <p>i just want to upload a file using jersey rest service and Jquery ajax as client here is my code
  1. HTML</p>
  
  <pre><code>&lt;form action="rest/file/upload" method="post" enctype="multipart/form-data"&gt;
  
     &lt;p&gt;
      Select a file : &lt;input type="file" name="file" /&gt;
     &lt;/p&gt;
  
     &lt;input type="submit" value="Upload It" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>2.Rest Service</p>
  
  <pre><code>@POST
  @Path("/upload")
  @Consumes(MediaType.MULTIPART_FORM_DATA)
  public Response uploadFile(@FormDataParam("file") InputStream stream) {
  
      String uploadedFileLocation = "E:\\\\uploaded\\test.jpg";
      //Session s = Session.getDefaultInstance(new Properties());
      //InputStream is = new ByteArrayInputStream(&lt;&lt; String to parse &gt;&gt;);
      //MimeMessage message = new MimeMessage(s, stream);
      //Multipart multipart = (Multipart) message.getContent();
      // save it
  
  
  
      writeToFile(stream, uploadedFileLocation);
  
  
      String output = "File uploaded to : " + uploadedFileLocation;
  
      try {
  
          stream.close();
      } catch (IOException e) {
          e.printStackTrace();
      }
  
      return Response.status(200).entity(output).build();
  
  }
  
  // save uploaded file to new location
  private void writeToFile(InputStream uploadedInputStream,
          String uploadedFileLocation) {
  
      try {
          byte[] image = IOUtils.toByteArray(uploadedInputStream);
  
  
          OutputStream out = new FileOutputStream(new File(uploadedFileLocation));
  
          IOUtils.write(image, out);
  
          /*int read = 0;
          byte[] bytes = new byte[1024];
  
          while ((read = uploadedInputStream.read(bytes)) != -1) {
              out.write(bytes, 0, read);
          }*/
          out.flush();
          out.close();
      } catch (IOException e) {
  
          e.printStackTrace();
      }
  
  }
  </code></pre>
  
  <p>its working but stream includes this line also</p>
  
  <pre><code>-----------------------------7dd3b827a0ddc
  </code></pre>
  
  <p>Content-Disposition: form-data; name="file"; filename="Jellyfish.jpg"
  Content-Type: image/pjpeg</p>
  
  <p>how to remove this from inputstream?
  need expertise answers</p>