I came a little closer by making custom http:headers, but I have to confess I'm in deep water here:
declare %rest:path("/download/{$file}") function page:download-file($file) { rest:response <http:response status="200" message="OK">
<http:header name="Content-Disposition" value="Attachment"/> <http:header name="filename" value="{$file}"/> </http:response> </rest:response>
};
This function do trigger a download of a file with the appropriate file name (=$file) containing the text OK. If I just could find somewhere in this code to put the contents of file, it should solve the problem.
Best, Lars
2014-08-21 15:20 GMT+02:00 Lars Johnsen yoonsen@gmail.com:
I am using BaseX restxq for accessing a repository from a web browser. Uploading files works smoothly, but I can't see how to make a download button work. For uploading, the recipie on the restxq help page was enough to get it to work. Is there a corresponding way for making downloading work? What I have tried is to let BaseX send a html-page containing:
<form method="get" action="/download/{$file}"> <button type="submit">Download</button> </form>
To process this form is the following restfunction
declare %rest:path("/download/{$file}") %output:method("html") function page:download-file($file) { ... }
Inside the curly braces, I have tried an <a href..> element and file:read-binary, but none of them with any success. BaseX complains about the <a> element, and file:read-binary outputs directly to the browser.
Any suggestions?