When I try to do file upload in JAX-RS Jersey, I am getting an error 415 Unsupported Media Type. I have attached the code and the configuration files that I have used, could anyone help me with this, please.I also tried to annote the class with @MultipartConfig. I am not passing any header in Postman.
Remvoing FormDataContentDisposition will remove the error and file upload works but i want to know why exactyly FormDataContentDisposition doesnt work in my code
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@OAuthSecurity(enabled = false)
@Path("/upload")
public Response postForm(
@FormDataParam("file") InputStream file,
@FormDataParam("file") FormDataContentDisposition fileDisposition) {
return Response.ok().build();
}
My pom.xml
<dependencies>
<!-- https://mvnrepository.com/artifact/com.ibm.mfp/adapter-maven-api -->
<dependency>
<groupId>com.ibm.mfp</groupId>
<artifactId>adapter-maven-api</artifactId>
<version>8.0.2018071507</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.0.4.RELEASE</version>
<type>jar</type>
</dependency>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-io -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.ibm.mfp/mfp-java-token-validator -->
<dependency>
<groupId>com.ibm.mfp</groupId>
<artifactId>mfp-java-token-validator</artifactId>
<version>8.0.2017020112</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.ibm.mfp/mfp-security-checks-base -->
<dependency>
<groupId>com.ibm.mfp</groupId>
<artifactId>mfp-security-checks-base</artifactId>
<version>8.0.2018030404</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<!-- optional, good for handle I/O task -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.4</version>
</dependency>
**<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.5.1</version>
</dependency>**
</dependencies>
I have a Main class that extends Application
public class MainApplication extends Application {
void init() throws Exception {
//class loading intitalization
log.info("Initialized");
}
void destroy() throws Exception {
log.info("destroyed!");
}
String getPackageToScan() {
// The package of this class will be scanned (recursively) to find JAX-RS resources.
return getClass().getPackage().getName();
}
}
there is no other configurations class added, there is no web.xml file also.