Hi Erik,
You have found some issues managing "multipart/form-data" that
contains multiple body parts of the same name (plus the same for cases
if all the body parts for files are encapsulated in a "multipart/
mixed").
Could you please log an issue against Jersey?
The use of the type MimeMultipart or the Jersey multipart API and the
type FormDataMultiPart should work:
https://jersey.dev.java.net/source/browse/*checkout*/jersey/tags/jersey-1.0.2/api/contribs/jersey-multipart/index.html
For example:
@Path("form-data")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@POST
public void uploadUrlFormData(
FormDataMultiPart f) throws IOException, ParseException {
try {
for (BodyPart bp : f.getBodyParts()) {
System.out.println(bp.getMediaType());
System.out.println(bp.getHeaders().get("Content-
Disposition"));
System.out.println(bp.getParameterizedHeaders().getFirst("Content-
Disposition").getParameters().get("name"));
bp.cleanup();
}
} finally {
f.cleanup();
}
}
But this is not as nice as using @FormParam.
In general i think we need to support a different annotation for
extracting information from multipart/form-data, rather than
overloading @FormParam. This will avoid confusion over certain
behaviors like managing lists of stuff, and expectations of what types
are supported.
So i would like to deprecate the use of @FormParam for "multipart/form-
data" and move functionality over to the Jersey multipart module and
use another annotation, say @FormDataParam.
Paul.
On Mar 6, 2009, at 3:36 PM, glassfish_at_javadesktop.org wrote:
> 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>