Gili wrote:
> Hi,
>
> Can someone please explain the difference between these two mime types? I
> see Jersey-multipart defaults to multipart/mixed but it isn't clear to me
> what this provides over multipart/form-data which is more common in the HTML
> world (and probably has better support).
>
> Thanks,
> Gili
>
The "multipart/form-data" media type was originally introduced in RFC
1867 for "Form-based File Upload in HTML". The details of the semantics
were very specific to that use case ... for example, the use of "name"
parameters on the Content-Disposition header of each body part, to map
to the corresponding HTML input field.
The "multipart/mixed" (and other similar types) media type was
explicitly designed to formalize the transport of related collections of
body entities in the same message ... the classic use case being email
attachments. These media types were explicitly designed to be more
general, so they do not impose any use-case-specific restrictions on
things like requiring certain headers with certain parameters. The
definitions are in RFC 2046 through 2049.
Although jersey-multipart will do just fine sending or receiving
"multipart/form-data" messages, the restrictions on
"multipart/form-data" semantics make it an unsuitable default media type
for a newly created MultiPart instance that is intended for general
purpose use.
If you want to use multipart/form-data, simply change your create
statement from:
MultiPart multiPart = new MultiPart();
to
MultiPart multiPart = new MultiPart(MediaType.MULTIPART_FORM_DATA_TYPE);
or even
MultiPart multiPart = new
MultiPart().type(MediaType.MULTIPART_FORM_DATA_TYPE);
or, create yourself a simple subclass that sets the default
characteristics you want:
public class MultiPartFormData extends MultiPart {
public MultiPartFormData() {
super(MediaType.MULTIPART_FORM_DATA_TYPE);
}
}
and use that class instead.
Craig