users@jersey.java.net

[Jersey] How to pull filename out of FormDataMultiPart

From: jmandawg <jmandawg_at_hotmail.com>
Date: Wed, 23 Mar 2011 08:04:11 -0700 (PDT)

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.