Hello all,
I'm currently trying to implement a service for uploading Images to a
Basex db.
There is a frontend service that serves an HTML + Javascript page which
receives the upload as an AJAX call from the browser then POSTs the
request to the backend service for storing into the db.
There is no big issue when doing it directly by a command or a query.
I've been even able to do it by using the following code inside the
RestXQ of the frontend service:
client:connect("localhost", 1984, "user", "pass") ! client:query(.,
"db:store('files', '" || $name || "', .)", map{ "" : $file})
But when I POST the data to the backend RestXQ I always get the data
stored into the DB as *base64* encoded text which messes up the
successive retrieves.
This is the code I use on the backend:
declare
%rest:path("/service/files/{$name}")
%rest:POST("{$body}")
%rest:consumes("image/png", "image/jpg", "image/jpeg", "image/gif",
"image/svg+xml")
%output:method("text")
function m:upload-maps($userid as xs:string, $name as xs:string, $body
as item()){
let $stored := db:store("files", $name, $body)
return
<rest:response>
<http:response status="201"/>
</rest:response>
};
I call this service from the frontend service with the following request
where the media-type is according to the uploaded file extension:
<http:request href="{$url}" method="POST">
<http:body media-type="image/png">
{$data}
</http:body>
</http:request>
How do I ensure that the data gets into the DB with its correct raw
binary format?
Thanks,
Marco.