users@jersey.java.net

Re: [Jersey] Documentation / Tutorial on using jersey-multipart

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 17 Dec 2008 10:56:21 +0100

On Dec 16, 2008, at 7:08 PM, Craig McClanahan wrote:

> Paul Sandoz wrote:
>> Hi Craig,
>>
>> I think your example reflects that we could do more to support
>> multupart/form-data with the multipart module.
> Agreed. This media type wasn't my initial priority, but we should
> definitely make sure it is supported elegantly.
>
>>
>> For an outbound message we need a way to easily set the content
>> disposition and its properties, including the name.
>>
> There is a way to do this today, but doesn't really count as elegant:
>
> BodyPart bp = ...;
> bp.getHeaders().putSingle("Content-Disposition", "form-data;
> name=" + filename);
>
> A BodyPart subclass that set this header automatically, and offered
> a property to set the filename, would be straightforward.
>
>
>> For an inbound message we need a way to easily get the body part
>> given a name that corresponds to the name property a content
>> disposition of a body part.
>>
> Again, you can do it with the existing code today, but you have to
> scan all the body parts, and use getParameterizedHeaders(), to look
> for fields by name.
>> Do we need to extend MultPart with FormDataMultPart ? and BodyPart
>> with FormDataBodyPart ?
>>
> I think this would definitely help. I've got a bit of time this
> week where I can take a deeper look.
>> Maybe a class that extends MultiPart class for managing a set of
>> files? as clients can upload a set of files using multipart/mixed?
>>
> What particular use cases are you thinking about here? I'll be
> looking at the HTML spec section you quote below, but it would be
> helpful to get a general idea of what you'd like.

An ease of use thing making sure that the content disposition of each
part of the multipart mixed is:

   Content-Disposition: file; filename="file1.txt"

with the ability to set the file names.


>
>> I am deriving cases from here:
>>
>> http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2
>>
>> We have a headers for ContentDisposition and
>> FormDataContentDisposition for parsing but there is no support yet
>> for writing.
> That would appear to be the case for all of the header classes, not
> just these two.

For some it works, like MediaType etc see
RuntimeDelegate,createHeaderDelegate.

https://jsr311.dev.java.net/nonav/javadoc/javax/ws/rs/ext/RuntimeDelegate.html
#createHeaderDelegate(java.lang.Class)


> Does it make sense to consider dealing with all of them?


Yes, we need to be consistent for all of them.

Paul.