users@jersey.java.net

Re: [Jersey] Working with binary files (images/files, etc) via REST

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Tue, 7 Sep 2010 19:00:00 -0700

On Tue, Sep 7, 2010 at 6:15 PM, Craig McClanahan <craigmcc_at_gmail.com> wrote:

>
>
> On Tue, Sep 7, 2010 at 5:18 PM, Kevin Duffey <andjarnic_at_yahoo.com> wrote:
>
>> Hi all, Craig. Glad to see you're still part of this list. :)
>>
>> I like what you say, although I thought you built the add-on that I was
>> looking for on handling file upload/download.. which the link seems to be
>> broken right now on the jersey site to get to downloads.
>>
>> Anyway, the issue I have is that the XML sent in may include several
>> values at once, not just an image (or file). I thought that I could get away
>> with wrapping it in a CDATA block... I've not personally experienced on how
>> to turn a chunk of perhaps base64 encoded (or binhex) binary data from a
>> CDATA chunk, especially via a Jersey call. But it would allow me to accept a
>> chunk of XML that contains multiple values. It doesn't have to be this way,
>> it would just make it more in line with the rest of how my XSD works. For
>> that matter, can you even specify an XSD element that pertains to binary
>> data and have it work with the Jersey/JAXB, so that I can accept it via a
>> method in that manner?
>>
>> If you're trying to include the binary data inside your XML document
> itself, AFAIK you'll need to base64 encode it or something (which means
> that, from the Jersey perspective, it's just a string field). That's an XML
> thing, not really a Jersey or JAX-RS thing.
>
>

I think it's actually just fine to define field as byte[], since JAXB should
be able to figure out how to use base64 encoding. And then it's mostly just
JAXB thing, as XML parser need not know how text segment is to be handled
(JAXB could make use of features of some parser to use more efficient
methods but not implementation support for those).

Same is true for JSON as well.

-+ Tatu +-