title: How to accept Form Params with multipart file upload
body: <p>I'm working on a REST application hosted on a Liberty server that should allow support for file upload. As a part of this POST request, I'd like to allow the user to specify a few things with Form parameters. Despite using the example from IBM <a href="https://www.ibm.com/support/knowledgecenter/en/SSEQTP_8.5.5/com.ibm.websphere.wlp.doc/ae/twlp_jaxrs_multipart_formdata_from_html.html" rel="nofollow noreferrer">here</a>, I can't quite get it to work. I can retrieve information related to the uploaded File using headers (like in the example). But when I try the same method to retrieve information about the headers, the only thing available is the name of the fields, but not their values.<br>
  I'm also trying to maintain support for Swagger..<br>
  Here's a snippet of my code:  </p>
  
  <pre><code>@ApiOperation("Upload Source Code to Build")
  @POST
  @Path("/")
  @Consumes(MediaType.MULTIPART_FORM_DATA)
  @Produces(MediaType.MULTIPART_FORM_DATA)
  @ApiResponses({
      @ApiResponse(code = 200, message= "OK", response=String.class)})
  @ApiImplicitParams({
      @ApiImplicitParam(
              name="source", 
              value = "Source File", 
              required = true, 
              dataType = "java.io.File", 
              paramType = "form", 
              type="file"),
      @ApiImplicitParam(
              name="archive_name", 
              value = "Name of File to Retrieve", 
              required = true, 
              dataType = "java.lang.String", 
              paramType = "form", 
              type="string"),
      @ApiImplicitParam(
              name="build_command", 
              value = "Command to Run", 
              required = true, 
              dataType = "java.lang.String", 
              paramType = "form", 
              type="string")})
  public Response uploadFileBuildArchive(
          @ApiParam(hidden=true) IMultipartBody multipartBody,
          @Context UriInfo uriInfo) throws IOException {
      List&lt;IAttachment&gt; attachments = multipartBody.getAllAttachments();
      InputStream stream = null;
      Iterator&lt;IAttachment&gt; it = attachments.iterator();
      IAttachment attachment = it.next();
  
      if (attachment == null)
          return Response.status(400).entity("No file attached").build();
  
      StringBuilder fileName = new StringBuilder("");
      StringBuilder archiveName = new StringBuilder("");
      StringBuilder buildCommand = new StringBuilder("");
  
      for(int i = 0; it.hasNext(); i++) {
          DataHandler dataHandler = attachment.getDataHandler();
          MultivaluedMap&lt;String, String&gt; map = attachment.getHeaders();
          String[] contentDisposition = map.getFirst("Content-Disposition").split(";");
  
          if(i == 0) {
              stream = dataHandler.getInputStream();
              Response saveFileResponse = handleFileStream(contentDisposition, stream, fileName);
              if (saveFileResponse != null)
                  return saveFileResponse;
          } else if (i == 1) {
              if (!handleFormParam(contentDisposition, archiveName))
                  return Response.status(400).entity("Missing FormParam: archive_name").build();
          }
      .
      .
      .
  private boolean handleFormParam(String[] contentDisposition, StringBuilder stringBuilder) {
      String formElementName = null;
      for (String tempName : contentDisposition) {
          String[] names = tempName.split("=");
          for (String n : names) {
              System.out.println(tempName + ":" + n);
          }
      }
      if (stringBuilder.length() == 0) {
          return false;
      }
      return true;
  }
  </code></pre>
  
  <p>The only information about the "archive_name" form param I can get from the attachment is that the name of the param is "archive_name". How do I get the value associated with "archive_name"?</p>