users@glassfish.java.net

Jersey multipart/form-data, can _at_FormParam support arrays?

From: <glassfish_at_javadesktop.org>
Date: Fri, 06 Mar 2009 06:36:30 PST

I would like to POST several files from a HTML form with the same param name, "pictures".

<form action=" http://localhost:8080/pictures" method="post" enctype="multipart/form-data">
<p>Pictures:
<input type="file" name="pictures" />
<input type="file" name="pictures" />
<input type="file" name="pictures" />
To: <input type="text" name="to"/>
<input type="submit" value="Send" />
</p>
</form>

And then use Jersey like this e.g.

@POST
    @Path("pictures")
    @Consumes("multipart/form-data")
    public void upload(
            @FormParam("pictures") List<InputStream> messages,
            @FormParam("to") String to
            ) throws IOException{


            for (Iterator<InputStream> it = messages.iterator(); it.hasNext();) {
            InputStream inputStream = it.next();
            File test = new File("c:/temp/" + getTimestamp()+ ".jpg");
            saveStreamToFile(inputStream, test);
            }

    }

However I can't find any information if or how Jersey supports this. Right now with this code above I just get a NullPointerException.

If I just specify @FormParam("pictures") InputStream messages , the InputStream messages only contains the last file from the form.

if I instead use

public void upload(javax.mail.internet.MimeMultipart multiPart)

the "to" param is not included in the multiPart, only the files. Why?
[Message sent by forum member 'erkap' (erkap)]

http://forums.java.net/jive/thread.jspa?messageID=335532