0

I am using eXist-db and I am trying to download a picture and save it on local disk with XQuery. I have trIed the following code:

declare namespace xmldb="http://exist-db.org/xquery/xmldb";

import module namespace http="http://exist-db.org/xquery/httpclient";
import module namespace util="http://exist-db.org/xquery/util";

let $url :=
    "https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png"
let $response := http:get(xs:anyURI($url), true(), <Headers/>)
let $picture := util:base64-decode($response//httpclient:body)
return 
    xmldb:store("/db/apps/places", "picture.png", $picture)

The above code downloads the picture, but when I try to open the image, I get an error.

I hope to have explained my problem well.

Joe Wicentowski
  • 5,159
  • 16
  • 26
Elkin
  • 880
  • 2
  • 12
  • 26

1 Answers1

2

See my fully commented, working sample code for downloading a file over HTTP and storing it in eXist-db at https://gist.github.com/joewiz/5938909.

Joe Wicentowski
  • 5,159
  • 16
  • 26