Hi,
I am trying to get a simple file upload to work with Jersey. I have seen some posts related to this. I started using the contrib multipart package and then saw the post here:
http://n2.nabble.com/File-upload-with-Jersey-td2377844.html
Is there a preferred way to handle this? I just need to handle one file at a time.
I went with the FormParam approach, starting with the method below. But, I get an exception. I tried this with and without the jersey-multipart-1.1.4.jar and mimepull-1.2.jar.
@Consumes(MediaType.MULTIPART_FORM_DATA)
@POST
@Produces("text/plain")
public String upload(@FormParam("file") InputStream fileInputStream,
/*_at_FormParam("file") FormDataContentDisposition contDisp,*/
@FormParam("title") String title,
@FormParam("description") String description) {
System.out.println("fileInputStream: " + fileInputStream);
//System.out.println("contDisp: " + contDisp);
System.out.println("title: " + title);
System.out.println("description: " + description);
return "boo";
}
But, I get the following exception when POSTing to it:
SEVERE: Allocate exception for servlet JerseyRest
com.sun.jersey.api.container.ContainerException: Method, public java.lang.String freshstory.ripple.rest.Uploader.upload(java.io.InputStream,java.lang.String,java.lang.String), annotated with POST of resource, class freshstory.ripple.rest.Uploader, is not recognized as valid Java method annotated with @HttpMethod.
at com.sun.jersey.server.impl.model.method.ResourceHttpMethod.<init>(ResourceHttpMethod.java:92)
at com.sun.jersey.server.impl.model.method.ResourceHttpMethod.<init>(ResourceHttpMethod.java:69)
at com.sun.jersey.server.impl.model.method.ResourceHttpMethod.<init>(ResourceHttpMethod.java:61)
at com.sun.jersey.server.impl.model.ResourceClass.processMethods(ResourceClass.java:302)
at com.sun.jersey.server.impl.model.ResourceClass.<init>(ResourceClass.java:132)
at com.sun.jersey.server.impl.application.WebApplicationImpl.newResourceClass(WebApplicationImpl.java:410)
at com.sun.jersey.server.impl.application.WebApplicationImpl.getResourceClass(WebApplicationImpl.java:373)
at com.sun.jersey.server.impl.application.WebApplicationImpl.processRootResources(WebApplicationImpl.java:928)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:714)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:445)