title: REST API involving file upload in java
body: <p>I have a Jersey REST API. I want to be able to send a JSON post request to the server with parameters</p>
  
  <pre><code>{ name:"abc", description:"test"} . 
  </code></pre>
  
  <p>ALong with these parameters, I also want to send a file through my post request. I am not sure how to achieve following:</p>
  
  <ol>
  <li>To send file and other parameters in a single JSON object on the client side. <br/></li>
  <li>To receive them on the server side. </li>
  </ol>
  
  <p>I have read that <code>MULTIPART_FORM_DATA</code> can be used for this. Need help to determine how to use it.</p>
  
  <p>My server code is </p>
  
  <pre><code>@POST
  @Produces(MediaType.APPLICATION_JSON)
  @Consumes(MediaType.APPLICATION_JSON)
  public Response create(JSONObject input) {
    ObjectMapper mapper = new ObjectMapper();
    Simulation config = mapper
     .readValue(input.toString(), Simulation.class);
    if (!CreateSimulation.isVaild(config))
    {
      ResponseBuilder builder = Response.status(Response.Status.BAD_REQUEST);
      builder.entity("Bad Request: Wrong Parameters");
      Response response = builder.build();
      throw new WebApplicationException(response);
    }
    int id = CreateSimulation.create(config);
    JSONObject output = new JSONObject();
    output.put("simulation-id", id + "");
    return Response.ok(output.toString(), MediaType.APPLICATION_JSON).build();
  }
  </code></pre>