Hi Christian, I'm using Basex 8.5.1 and this is a faithful excerpt of the code:
module namespace ssce = "urn:ssce";
declare %basex:inline function ssce:upload-impl($name as xs:string, $data as item()){ let $f := file:write-binary("/tmp/" || $name, $data) let $response := http:send-request( <http:request method="POST">, <http:body media-type="{web:content-type($name)}"/> </http:request>, "http://localhost:10000", $data ) return if($response[1]/@status = 201) then () else error(xs:QName("error"),"Error sending") };
declare %rest:path("/ssce/{$name}") %rest:POST("{$body}") %rest:consumes("image/png", "image/jpg", "image/jpeg", "image/gif") %output:method("text") function ssce:upload($name as xs:string, $body as item()){ ssce:upload-impl($name, $body) };
This is the curl I use to upload an image:
curl --data-binary @image.png http://localhost:9984/ssce/nubis.png -H"Content-type:image/png"
And again the file:write-binary writes the png to file but opening a nc -l I can see that the request is base64 encoded.
Thanks for any hint, Marco.
On 11/08/2016 12:26, Christian GrĂ¼n wrote:
let $f := file:write-binary("/tmp/" || $name, $map)
Is it supposed to be $body? What happens if you use CURL?
It works perfectly on my system. Could you possibly provide me with a self-contained example?
Christian