[basex-talk] Downloading files

2014-08-21 Thread Lars Johnsen
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=submitDownload/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?


Re: [basex-talk] Downloading files

2014-08-21 Thread Andy Bunce
Hi Lars,
You need to return a sequence of two items: (restxq:response,thedata)
I do something like...

declare
  %rest:path(/download/{$file})
  function page:download-file($file)
  {
   (download-response(raw,$file), file:read-binary(..))
  };

(:~ headers for download  :)
declare function download-response($method,$filename){
restxq:response
output:serialization-parameters
output:method value={$method}/
/output:serialization-parameters
   http:response
   http:header name=Content-Disposition
value='attachment;filename={$filename}'/
/http:response
/restxq:response
};

/Andy


On 21 August 2014 15:40, Lars Johnsen yoon...@gmail.com wrote:

 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 yoon...@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=submitDownload/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?






Re: [basex-talk] Downloading files

2014-08-21 Thread Lars Johnsen
Thanks a lot Andy! It works like a charm. Now the filename can be
manipulated as well. Perfect!

Best,
Lars


2014-08-21 17:10 GMT+02:00 Andy Bunce bunce.a...@gmail.com:


 Hi Lars,
 You need to return a sequence of two items: (restxq:response,thedata)
 I do something like...

 declare
   %rest:path(/download/{$file})
   function page:download-file($file)
   {
(download-response(raw,$file), file:read-binary(..))
   };

 (:~ headers for download  :)
 declare function download-response($method,$filename){
 restxq:response
 output:serialization-parameters
 output:method value={$method}/
 /output:serialization-parameters
http:response
http:header name=Content-Disposition
 value='attachment;filename={$filename}'/
 /http:response
 /restxq:response
 };

 /Andy


 On 21 August 2014 15:40, Lars Johnsen yoon...@gmail.com wrote:

 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 yoon...@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=submitDownload/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?