title: Handling multipart attachments in CXF APIs
body: <p>I am trying to develop an API call using Apache CXF that takes in an attachment along with the request. I followed <a href="http://cxf.apache.org/docs/jax-rs-multiparts.html" rel="nofollow">this</a> tutorial and this is what I have got so far.</p>
  
  <pre><code>@POST
  @Path("/upload")
  @RequireAuthentication(false)
  public Response uploadWadl(MultipartBody multipartBody){
      List&lt;Attachment&gt; attachments = multipartBody.getAllAttachments();
      DataHandler dataHandler = attachments.get(0).getDataHandler();
      try {
          InputStream is = dataHandler.getInputStream();
      } catch (IOException e) {
          e.printStackTrace();
      }
      return Response("OK");
  }
  </code></pre>
  
  <p>I am getting an InputStream object to the attachment and everything is working fine. However I need to pass the attachment as a java.io.File object to another function. I know I can create a file here, read from the inputstream and write to it. But is there a better solution? Has the CXF already stored it as a File? If so I could just go ahead and use that. Any suggestions?</p>