users@jersey.java.net

[Jersey] Re: Question about multipart upload

From: Rindt, Daniel <drindt_at_viselabs.com>
Date: Mon, 8 Dec 2014 15:02:41 +0100

Thank you for all repliers to my question. I have solved this.

Daniel

2014-12-04 18:03 GMT+01:00 Michael Pratt <prattm_at_gmail.com>:

> What's the actual problem you have? Are there error messages? Are the
> query parameters and/or form data fields not being bound properly? Or are
> you just looking for an example?
>
> We have a resource that accepts form/multi-part data with images. Here is
> how we declare our resources:
>
> @POST
> @Path("/{userId}/{projectId}")
> @Consumes(MediaType.MULTIPART_FORM_DATA)
> public Response addGraphicToProject(
> @PathParam("userId") int userId,
> @PathParam("projectId") int albumId,
> final FormDataMultiPart multiPartFormData,
> @QueryParam("caption") String imageCaption,
> @Context UriInfo ui)
> {
> // Get the image data from the message body
> FormDataBodyPart imageFile = multiPartFormData.getField("imageFile");
> String mimeType = imageFile.getMediaType().toString();
> InputStream imageStream = imageFile.getValueAs(InputStream.class);
>
> // Then we copy the InputStream to a ByteArrayOutputStream to get the
> raw byte[]
> }
>
> This might be not be the most efficient, but works well for us. As for
> configuration, we have the following two things in place that you may need:
>
> In our POM file, we have:
>
> <dependency>
> <groupId>org.glassfish.jersey.media</groupId>
> <artifactId>jersey-media-multipart</artifactId>
> <version>2.12</version>
> </dependency>
>
> And in our servlet config (we use tomcat 7) we have:
> <init-param> <param-name>jersey.config.server.provider.classnames</
> param-name> <param-value
> >org.glassfish.jersey.media.multipart.MultiPartFeature</param-value> </
> init-param>
> Mike
>
> Mike
>
> On Thu, Dec 4, 2014 at 8:05 AM, Santiago Pericas-Geertsen <
> Santiago.PericasGeertsen_at_oracle.com> wrote:
>
>>
>> I don't have a running example, but basically you need:
>>
>> @FormDataParam("foo") InputStream foo
>>
>> This example may help:
>>
>>
>> http://examples.javacodegeeks.com/enterprise-java/rest/jersey/jersey-file-upload-example/
>>
>> -- Santiago
>>
>> On Dec 4, 2014, at 9:54 AM, Rindt, Daniel <drindt_at_viselabs.com> wrote:
>>
>> 2014-12-04 15:35 GMT+01:00 Santiago Pericas-Geertsen
>> <Santiago.PericasGeertsen_at_oracle.com>:
>>
>> Dear Santiago,
>>
>> thanks for your reply.
>>
>> If you don't have the multipart running, there's Jersey sample for that
>> (multipart-webapp). If you do have it running, what is the issue with just
>> adding some @QueryParam's in your code?
>>
>>
>> I am simply unsure what i have to do to receive images there. I have
>> seen so many examples and tried so much. Can you please provide me an
>> example? In my case i expect from the client
>> one or more photos as upload. FormDataMultipart was helpful in the
>> local environment but doesn't work in the real appengine. So i moved
>> to Jersey 2. But there is no FormDataMultipart
>> anymore.
>>
>> It would be really nice to provide such example how to obtain an
>> InputStream of the uploaded Multipart element.
>>
>> Thank you very much.
>> Daniel
>>
>> -- Santiago
>>
>> On Dec 3, 2014, at 5:47 PM, Rindt, Daniel <drindt_at_viselabs.com> wrote:
>>
>> Dear reader,
>>
>> i'm using jersey 2.13 including the multipart packages. The
>> application is deployed to appengine and should receive multiple
>> images. Alongside the images are posted few parameters (@QueryParam)
>> not as multipart. I tried to do my homework and looked for example
>> code also the examples from github but i wasn't successful.
>> So my question is: can someone please point me to example code which do
>> this?
>>
>> I am very thankful for all hints and suggestions.
>>
>> Kind Regards,
>> --
>> Daniel Rindt
>> Viselabs e. K.
>> mobile software solutions
>> Berlin, Germany
>>
>> phone: +4930202368410
>> fax: +4930202368411
>>
>> entered in the commercial register at the local court of Berlin under HRA
>> 46662B
>>
>>
>>
>>
>>
>> --
>> Daniel Rindt
>> Viselabs e. K.
>> mobile software solutions
>> Berlin, Germany
>>
>> phone: +4930202368410
>> fax: +4930202368411
>>
>> entered in the commercial register at the local court of Berlin under HRA
>> 46662B
>>
>>
>>
>


-- 
Daniel Rindt
Viselabs e. K.
mobile software solutions
Berlin, Germany
phone: +4930202368410
fax: +4930202368411
entered in the commercial register at the local court of Berlin under HRA
46662B