Send byte[] to http response ?

Thursday, 7 May 2020 · 2 messages
MD
Mickael Desfrenes7 May 2020 17:03 #
Hello, Probably my ignorance, but I struggle to send a byte array (byte[]) from a java module to a restxq response. Something a bit like this:
        return
        (<rest:response>
            <http:response status="200">
                <http:header name="content-type" value="application/pdf"/>
            </http:response>
        </rest:response>,
        SomeJavaModule:getSomeBytes($module_instance))
I know there is a binary module in BaseX but I tried various things and couldn't get the wanted output. I could probably write the bytes in a file and then use file:read-binary() but it's something I'd like to avoid. Any clue here ? Mickaël
CG
Christian Grün7 May 2020 17:55 #
Hi Mickaël, You might need to convert the resulting byte sequence to a xs:base64Binary item:
  convert:integers-to-base64(
    Q{java:java.lang.String}get-bytes('xyz')
  )
If that doesn’t help, feel free to provide us with your full RESTXQ function. Best, Christian
Quoted text · Mickael Desfrenes · 25 lines
On Thu, May 7, 2020 at 5:03 PM Mickael Desfrenes <mickael.desfrenes at unicaen.fr> wrote: > > Hello, > > Probably my ignorance, but I struggle to send a byte array (byte[]) from a java module to a restxq response. > > Something a bit like this: > > return > (<rest:response> > <http:response status="200"> > <http:header name="content-type" value="application/pdf"/> > </http:response> > </rest:response>, > SomeJavaModule:getSomeBytes($module_instance)) > > I know there is a binary module in BaseX but I tried various things and couldn't get the wanted output. > I could probably write the bytes in a file and then use file:read-binary() but it's something I'd like to avoid. > > Any clue here ? > > Mickaël > >

⚡Generated with XQuery