title: How to get multipartentity from httpservletrequest
body: <p>I am trying to invoke a webservice from java spring controller. Below is the code</p>
  
  <pre><code>private void storeImages(MultipartHttpServletRequest multipartRequest) {
      DefaultHttpClient httpClient = new DefaultHttpClient();
      HttpPost postRequest = new HttpPost(
                      "http://localhost:8080/dream/storeimages.htm");
      MultipartFile multipartFile1 = multipartRequest.getFile("file1");
      MultipartEntity multipartEntity = new MultipartEntity(
                      HttpMultipartMode.BROWSER_COMPATIBLE);
      multipartEntity.addPart("file1",
                      new ByteArrayBody(multipartFile1.getBytes(),
                                      multipartFile1.getContentType(),
                                      multipartFile1.getOriginalFilename()));
      postRequest.setEntity(multipartEntity);
      HttpResponse response = httpClient.execute(postRequest);
      if (response.getStatusLine().getStatusCode() != 201) {
          throw new RuntimeException("Failed : HTTP error code : "
                          + response.getStatusLine().getStatusCode());
      }
  }
  </code></pre>
  
  <p>Above is just partial code. I am trying to determine how to retrieve this on the server side. On the server side i have the following Spring controller code</p>
  
  <pre><code>@RequestMapping(value = "/storeimages.htm", method = RequestMethod.POST)
  public ModelAndView postItem(HttpServletRequest request,
                  HttpServletResponse response) {
      logger.info("Inside /secure/additem/postitem.htm");
      try {
          // How to get the MultipartEntity object here. More specifically i
          // want to get back the Byte array from it
      } catch (Exception ex) {
          ex.printStackTrace();
      }
      return new ModelAndView("success");
  }
  </code></pre>
  
  <p>I executed this code and my control is going to the server side. But i am stuck on how to get back the byte array from the multipartentity object. </p>
  
  <p>Edited requirement:
  Here is the requirement. User uploads the images from website (This is done and working) The control goes to the Spring controller after form submit (This is done and working) In Spring controller I am using Multipart to get the content of the form. (This is done and working) Now i want to call a webservices which will send the image byte array to image server.(This needs to be done) On the image server, i want to receive this webservice request get all the fields from HTTPServlerRequest, store the images and return(This needs to be done)</p>