title: Consuming both MULTIPART_FORM_DATA and APPLICATION_JSON in same webservice java
body: <p>This is my code that saves image in directory:</p>
  
  <pre><code>@POST
  @Path("/imagestore")
  @Consumes(MediaType.MULTIPART_FORM_DATA)
  // @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public JSONObject uploadFile(@FormDataParam("file") InputStream file) {     
      String dirPath = servletContext.getContextPath()+"/images";
      File imagesDir = new File(dirPath);
      boolean dirCreated = true;
      if (!imagesDir.exists()) {
          try {
              dirCreated = imagesDir.mkdirs();
          } catch (Exception e) {
              e.printStackTrace();
          }           
      }
      if (dirCreated) {
          String filePath = dirPath + "/1.jpg";
          JSONObject obj = new JSONObject();
          // save the file to the server
          try {
              File newFile = new File(filePath);
              boolean fileCreated = true;
              if (!newFile.exists()) {
                  fileCreated = newFile.createNewFile();
              }
              if (fileCreated) {
                  FileOutputStream outpuStream = new FileOutputStream(newFile);
                  int read = 0;
                  byte[] bytes = new byte[1024];
  
                  while ((read = file.read(bytes)) != -1) {
                      outpuStream.write(bytes, 0, read);
                  }
                  outpuStream.flush();
                  outpuStream.close();
              }
          } catch (IOException e) {
              try {
                  obj.put("error", e.getMessage());
              } catch (JSONException e1) {
                  // TODO Auto-generated catch block
                  e1.printStackTrace();
              }
              e.printStackTrace();
          }
  
          String output = "File saved to server location : " + filePath;
  
          try {
              obj.put("output", output);
              return obj;
          } catch (JSONException e) {
              e.printStackTrace();
              return null;
          }
      }
      return obj;
  }
  </code></pre>
  
  <p>Now this works perfectly but i also need to save data to database and for that i need to consume Json data as well but i don't know how to do both these things are the same time because you can only write one consumes. 
  In Simple words i want to consume both json (containing user info) and Mulipart_form_data (containing image to upload on server) . So how do i do it.I'll appreciate the help :)</p>