Reputation: 328
I'm writing a web service to upload a image/video file to the server. Every time I call my upload web service from postman, it return 415 Unsupported Media Type. Here is what I have done.
In my controller:
@POST
@Path("/upload")
@Produces(MediaType.MULTIPART_FORM_DATA)
public Response upload(@RequestParam("file") MultipartFile files) {
Response.ResponseBuilder rb;
rb = Response.status(Response.Status.OK);
rb.entity(new ResponseWrapper<String>(SUCCESS, ""));
return rb.build();
}
application context:
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="10000000"/>
</bean>
I have already added commons-fileupload-1.2.2.jar
& mimepull.jar
When I call the web service I get the following console log.
com.sun.jersey.spi.container.ContainerRequest getEntity
SEVERE: A message body reader for Java class org.springframework.web.multipart.MultipartFile, and Java type interface org.springframework.web.multipart.MultipartFile, and MIME media type multipart/form-data; boundary=--------------------------410903058421289672087091 was not found.
The registered message body readers compatible with the MIME media type are:
multipart/* ->
com.sun.jersey.multipart.impl.MultiPartReaderServerSide
*/* ->
com.sun.jersey.core.impl.provider.entity.FormProvider
com.sun.jersey.core.impl.provider.entity.StringProvider
com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
com.sun.jersey.core.impl.provider.entity.FileProvider
com.sun.jersey.core.impl.provider.entity.InputStreamProvider
com.sun.jersey.core.impl.provider.entity.DataSourceProvider
com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General
com.sun.jersey.core.impl.provider.entity.ReaderProvider
com.sun.jersey.core.impl.provider.entity.DocumentProvider
com.sun.jersey.core.impl.provider.entity.SourceProvider$StreamSourceReader
com.sun.jersey.core.impl.provider.entity.SourceProvider$SAXSourceReader
com.sun.jersey.core.impl.provider.entity.SourceProvider$DOMSourceReader
com.sun.jersey.json.impl.provider.entity.JSONJAXBElementProvider$General
com.sun.jersey.json.impl.provider.entity.JSONArrayProvider$General
com.sun.jersey.json.impl.provider.entity.JSONObjectProvider$General
com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General
com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General
com.sun.jersey.core.impl.provider.entity.XMLRootObjectProvider$General
com.sun.jersey.core.impl.provider.entity.EntityHolderReader
com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$General
com.sun.jersey.json.impl.provider.entity.JSONListElementProvider$General
com.sun.jersey.json.impl.provider.entity.JacksonProviderProxy
I've tried many things digging the internet, still dosnt'e work. Help is appreciated.
Upvotes: 0
Views: 2351
Reputation: 1
There are two changes in suggest:
@produces
to @consumes
as this api is accepting the file which is multipart/form-data
.Upvotes: 0
Reputation: 13535
try setting the content type using the following format
rb.type(MediaType.TEXT_PLAIN)
change the media type accordingly to your needs. text_plain as provided in the example above should be setting text/plain
Upvotes: 0