users@jersey.java.net

[Jersey] Re: How to pull filename out of FormDataMultiPart

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Wed, 23 Mar 2011 16:34:07 +0100

hello,

please see multipart-webapp sample:

     @Path("part-file-name")
     @Consumes(MediaType.MULTIPART_FORM_DATA)
     @POST
     public String post(
             @FormDataParam("part") String s,
             @FormDataParam("part") FormDataContentDisposition d) {
         return s + ":" + d.getFileName();
     }

you will need to introduce another dependency (if you are not using it
already):

<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
<version>${project.version}</version>
<!--<scope>provided</scope>-->
</dependency>

Regards,
Pavel

On 03/23/2011 04:04 PM, jmandawg wrote:
> Hi all, i'm trying to upload a file to a jersey rest service. Here is my
> code:
>
> @POST
> @Path("/upload")
> @Consumes(MediaType.MULTIPART_FORM_DATA)
> public String doUpload(FormDataMultiPart data) {
>
> try{
> FileOutputStream fos = new FileOutputStream(new
> File("C:\\tmp\\test.tmp"));
> byte[] fileData = data.getField("Filedata").getValueAs(byte[].class);
> fos.write(fileData);
> fos.close();
> }
> catch(Exception ex)
> {
> ex.printStackTrace();
> }
> }
>
> My header looks like this:
>
> ------------Ef1ei4KM7ei4KM7GI3gL6KM7Ef1ei4
>
> Content-Disposition: form-data; name="Filedata";
> filename="2009_Calendar.xls"
>
> Content-Type: application/octet-stream
> binarydata.....
>
> My question is,
> How do i retrieve the value of filename??
>
>
> --
> View this message in context: http://jersey.576304.n2.nabble.com/How-to-pull-filename-out-of-FormDataMultiPart-tp6200588p6200588.html
> Sent from the Jersey mailing list archive at Nabble.com.
>