Hi Andrew,
It does seem like using multipart/mixed with Jersey MultiPart support
would be a better fit than using XML and base64 encoding (which is
grotesquely inefficient for large documents, although you could use
MTOM).
If you use multipart/mixed then clients are sort of "obligated" to
provide a Content-Type that declares the media type. Which leaves you
to deal with an edge case of when no Content-Type is present.
I am wondering if there is a simple utility in the JDK or JavaMail to
determine the media type from a sequence of bytes.
Paul.
On Feb 5, 2009, at 10:09 PM, Andrew Feller wrote:
> Craig,
>
> I read one of your earlier posts where you recommended using Java
> Mail API for MIME discovery, however I was looking for a way to
> determine MIME types from a java.io.File or java.io.InputStream. I
> am working on a Jersey REST resource that consumes XML that
> contains multiple Base64 encoded documents (PDFs, images, MS Office
> documents) and transforms them into PDFs. As you can guess, I need
> to determine whether a file is a PDF or not. I noticed the
> multipart project could do this with MultiPart objects, but didn’t
> know if there was a way to do it natively in Sun provided libraries.
>
> I also realized there could be some use for MultiPart utilities
> that could easily glean file attachment information such as file
> name instead of doing something like:
>
> MultiPart.getBodyParts().get(#).getParameterizedHeaders().get
> ("Content-Disposition").get(0).getParameters().get("filename"));
>
> Thanks and keep up the good work,
> Andrew
>
> On 2/5/09 1:37 PM, "Craig McClanahan" <Craig.McClanahan_at_Sun.COM>
> wrote:
>
>> Andrew Feller wrote:
>>> Re: [Jersey] Question: Best practices related to Eclipse project
>>> structure Craig,
>>>
>>> Very neat!
>>>
>>> Are you still working on the jersey-multipart project?
>> I am.
>>> If so, have you considered any type of utility classes for
>>> working with multipart attachments? Aside from the Java Mail API
>>> library, is there any library you recommend for determining MIME
>>> types from input streams?
>>>
>>>
>> Well, jersey-multipart already figures out the MIME types of each
>> body part for you -- see BodyPart.getMediaType() -- in fact, it
>> uses JavaMail under the covers to parse the incoming multipart
>> message bodies. Is there some particular functionality that you
>> think is missing?
>>> Thanks again Craig,
>>> Andrew
>>>
>>>
>> Craig
>>
>>
>
> --
> Andrew Feller, Analyst
> LSU University Information Services
> 200 Frey Computing Services Center
> Baton Rouge, LA 70803
> Office: 225.578.3737
> Fax: 225.578.6400