[XQZone General] Posting binary data - tricky?

Nick Lanham nick at marklogic.com
Tue Aug 16 10:54:05 PDT 2005


hi andy,

it is a bit tricky yes.  the main problem with just trying to quote your
binary data is that you might have (for example) null characters in it,
making it difficult to turn into a string.

an approach i've used is to turn the node into a base64 string of what
you want to post like so (data() on a binary node will base64 encode):

let $img := doc("foo.jpg")
return 
  xdmp:http-post("http://mywebservice:9000",
    <options xmlns="xdmp:http">
      <data>{data($img/node())}</data>
    </options>);

and then un-encode it on the other side.

hope that helps!

nick


On Tue, 2005-08-16 at 07:05, atownsen at wiley.co.uk wrote:
> 
> Ok smart folk..............
> 
> Platform : Mark Logic 3.0-2 on Solaris
> 
> I have binary objects in MarkLogic (e.g. a gif or jpeg image) - so far so
> good.
> 
> Now I wish to use an external service on them - watermark, thumbnail
> etc..... (stuff that I can't do within ML) so I want to send them via an
> HTTP Post to the service.
> 
> Should be easy (and is easy with XML content) however I don't appear to be
> able to put the data into the post because when I do something like:
> 
> .....
> let $postData :=
>         <options xmlns="xdmp:http">
>                 <data>
>                         { $data }
>                 </data>
>         </options>
> let $result as item()+ := xdmp:http-post($url, $postData)
> ......
> 
> I get   XDMP-CHILDNODEKIND: $data -- element nodes cannot have binary node
> children.
> 
> Ok - I understand that rule but how then can I post my binary data around
> from within ML?  Can I encode it somehow/somewhere?
> 
> I have tried xdmp:quote() (since it takes item()* and I hope - though as
> yet I find no docs -  a binary node should be a subtype of this) and indeed
> this seems to let me put the node into <options> but I then get the error
> below presumably as a part of the validation of <options> done in
> xdmp:http-post.
> 
> XDMP-NOTSIMPLE: xdmp:http-post(......., /http:options) -- Node does not
> have simple content: /http:options/http:data
> 
> I do concede that the docs for xdmp:http-post do state that options/data
> should be a string, but then xdmp:quote() is supposed to return a string.
> 
> So anyway - just how can I post my binary content off for processing,
> preferably without using unelegant write-to-the-filesystem type
> work-arounds?
> 
> Thanks in advance
> 
> Andy
> 
> 
> 
> 
> 
> ######################################################################
> The information contained in this e-mail and any subsequent 
> correspondence is private and confidential and intended solely 
> for the named recipient(s).  If you are not a named recipient, 
> you must not copy, distribute, or disseminate the information, 
> open any attachment, or take any action in reliance on it.  If you 
> have received the e-mail in error, please notify the sender and delete
> the e-mail.  
> 
> Any views or opinions expressed in this e-mail are those of the 
> individual sender, unless otherwise stated.  Although this e-mail has 
> been scanned for viruses you should rely on your own virus check, as 
> the sender accepts no liability for any damage arising out of any bug 
> or virus infection.
> ######################################################################
> _______________________________________________
> General mailing list
> General at xqzone.marklogic.com
> http://xqzone.com/mailman/listinfo/general




More information about the General mailing list