users@jersey.java.net

Re: [Jersey] file upload

From: Robert Koberg <rob.koberg_at_gmail.com>
Date: Tue, 17 Nov 2009 18:49:17 -0800

Ufff... I needed to use @FormDataParam instead of @FormParam

sorry for the noise...

-Rob



On Nov 17, 2009, at 6:43 PM, Robert Koberg wrote:

> Hi again,
>
> The method succeeds if I just use:
>
> public String upload(@FormParam("file") InputStream fileInputStream) {
> ...
> }
>
> How do you go about getting the other request params and also the filename?
>
> -Rob
>
>
>
> On Nov 17, 2009, at 6:02 PM, Robert Koberg wrote:
>
>> 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)
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>