title: Multipart file upload in IBM Mobilefirst Java HTTP Adapter
body: <p>I am a newbie to IBM Mobile-first java adapter,  I am trying to send an image file( Multipart request) to my java adapter (uses JAX-Rs) using Postman, and receive that image file in Rest API, and send it to third party server.</p>
  <p>But whenever I hit the API from the Postman I get 415 Unsupported media type error, I even tried configuring JAX-rs2.0 in MFPJAXRSApplication class, but that also doesn't work. Could anyone please help me with this.</p>
  <p>My main application class</p>
  <pre><code>package com.sample.adapter;
  
  import java.util.logging.Logger;
  import com.ibm.mfp.adapter.api.MFPJAXRSApplication;
  
  public class JavaAdapterApplication extends MFPJAXRSApplication{
  
      static Logger logger = Logger.getLogger(JavaAdapterApplication.class.getName());
  
      @Override
      protected void init() throws Exception {
          logger.info(&quot;Adapter initialized!&quot;);
      }
  
      @Override
      protected String getPackageToScan() {
          //The package of this class will be scanned (recursively) to find JAX-RS 2.0 resources.
          return getClass().getPackage().getName();
      }
  
      @Override
      public Set&lt;Class&lt;?&gt;&gt; getClasses() {
          
          
          log.info(&quot;********* added this part by following few suggestin of stack overflow ************&quot;);
          Set&lt;Class&lt;?&gt;&gt; resources = new java.util.HashSet&lt;Class&lt;?&gt;&gt;();
          resources.add(MultiPartFeature.class);
          addRestResourceClasses(resources);
          return resources;
      }
  
      /**
       * Do not modify addRestResourceClasses() method. It is automatically populated
       * with all resources defined in the project. If required, comment out calling
       * this method in getClasses().
       */
      private void addRestResourceClasses(Set&lt;Class&lt;?&gt;&gt; resources) {
          log.info(&quot;********* added this part by following few suggestin of stack overflow ************&quot;);
          resources.add(com.adapter.application.services.TestService.class);
      }
  }
  </code></pre>
  <p>My resource class is <strong>When I remove FormDataContentDisposition from the code and keep only Inputstrem I can reach the API but as soon as I add FormDataContentDisposition it starts with 415 unsupported media type error.</strong></p>
  <pre><code>import java.awt.AlphaComposite;
  import java.awt.Graphics2D;
  import java.awt.Image;
  import java.awt.image.BufferedImage;
  import java.io.File;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.nio.file.Files;
  
  import javax.imageio.ImageIO;
  import javax.servlet.http.HttpServletRequest;
  import javax.ws.rs.Consumes;
  import javax.ws.rs.POST;
  import javax.ws.rs.Path;
  import javax.ws.rs.Produces;
  import javax.ws.rs.core.Context;
  import javax.ws.rs.core.MediaType;
  import javax.ws.rs.core.Response;
  
  import org.apache.http.client.methods.HttpRequestBase;
  
  import com.adapter.util.CRGEHttpRequestGenerator;
  import com.adapter.util.CRGELogUtils;
  import com.adapter.util.CRGERequestHandler;
  import com.adapter.util.CRGEResponseHandler;
  import com.ibm.mfp.adapter.api.ConfigurationAPI;
  import com.ibm.mfp.adapter.api.OAuthSecurity;
  import com.ibm.mfp.server.security.external.resource.AdapterSecurityContext;
  
  import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
  import org.glassfish.jersey.media.multipart.FormDataMultiPart;
  import org.glassfish.jersey.media.multipart.FormDataParam;
  
  @Path(&quot;/hi&quot;)   
  public class TestService extends RequestHandler  {
      @Context
      AdapterSecurityContext securityContext;
      
      @Context
      static ConfigurationAPI configurationAPI;
  
      static org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(TestService.class.getName());
   
  
     @POST
  @Path(&quot;/uploadFeedback&quot;)
  @Consumes(MediaType.MULTIPART_FORM_DATA)
  @Produces(&quot;*/*&quot;)
  @OAuthSecurity(enabled=false)
  public Response  attachupload( @FormDataParam(&quot;file&quot;) InputStream uploadedInputStream,
          @FormDataParam(&quot;file&quot;) FormDataContentDisposition fileDetail){
      log.info(&quot;fileName&quot;+fileDetail);
      return Response.ok().build();
  }
  </code></pre>
  <p>Pom.xml</p>
  <pre><code>    &lt;properties&gt;
          &lt;!-- Use UTF-8 as the encoding of the adapter --&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
  
          
      &lt;/properties&gt;
  
       &lt;dependencies&gt;
          &lt;!-- https://mvnrepository.com/artifact/com.ibm.mfp/adapter-maven-api --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.ibm.mfp&lt;/groupId&gt;
              &lt;artifactId&gt;adapter-maven-api&lt;/artifactId&gt;
              &lt;version&gt;8.0.2018071507&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          
          &lt;!-- https://mvnrepository.com/artifact/org.springframework/spring-web --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
              &lt;version&gt;3.0.4.RELEASE&lt;/version&gt;
              &lt;type&gt;jar&lt;/type&gt;
          &lt;/dependency&gt;
          
          &lt;!-- https://mvnrepository.com/artifact/log4j/log4j --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;log4j&lt;/groupId&gt;
              &lt;artifactId&gt;log4j&lt;/artifactId&gt;
              &lt;version&gt;1.2.17&lt;/version&gt;
          &lt;/dependency&gt;
          
          &lt;!-- https://mvnrepository.com/artifact/org.apache.commons/commons-io --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
              &lt;artifactId&gt;commons-io&lt;/artifactId&gt;
              &lt;version&gt;1.3.2&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-annotations&lt;/artifactId&gt;
              &lt;version&gt;2.9.7&lt;/version&gt;
          &lt;/dependency&gt;
          
          &lt;!-- https://mvnrepository.com/artifact/com.ibm.mfp/mfp-java-token-validator --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.ibm.mfp&lt;/groupId&gt;
              &lt;artifactId&gt;mfp-java-token-validator&lt;/artifactId&gt;
              &lt;version&gt;8.0.2017020112&lt;/version&gt;
          &lt;/dependency&gt;
          
          &lt;!-- https://mvnrepository.com/artifact/com.ibm.mfp/mfp-security-checks-base --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.ibm.mfp&lt;/groupId&gt;
              &lt;artifactId&gt;mfp-security-checks-base&lt;/artifactId&gt;
              &lt;version&gt;8.0.2018030404&lt;/version&gt;
          &lt;/dependency&gt;
          
          &lt;!-- https://mvnrepository.com/artifact/com.google.code.gson/gson --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.google.code.gson&lt;/groupId&gt;
              &lt;artifactId&gt;gson&lt;/artifactId&gt;
              &lt;version&gt;2.8.5&lt;/version&gt;
          &lt;/dependency&gt;
  
      
      &lt;!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpmime --&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
      &lt;artifactId&gt;httpmime&lt;/artifactId&gt;
      &lt;version&gt;4.3.1&lt;/version&gt;
  &lt;/dependency&gt;
      
     
     
       &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.containers&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-container-servlet&lt;/artifactId&gt;
              &lt;version&gt;2.7&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.media&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-media-multipart&lt;/artifactId&gt;
              &lt;version&gt;2.7&lt;/version&gt;
          &lt;/dependency&gt;     
  
      &lt;/dependencies&gt;
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;com.ibm.mfp&lt;/groupId&gt;
                  &lt;artifactId&gt;adapter-maven-plugin&lt;/artifactId&gt;
                  &lt;extensions&gt;true&lt;/extensions&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  <p>I want to know why the server is not recognizing Multipart request,  do we have to configure the adapter to accept the multipart request, if yes then how do we configure it? Could anyone please save my life by helping me with this.</p>
  <p><em>Also my application does not have WEB.xml or any class that begins with @ApplicationPath</em></p>