dba/databases
library moduleR
Summary
Download resources.
- Tags
Author: Christian Grün, BaseX Team 2005-21, BSD License
__source : databases/resources/db-download.xqm
Imports
This module is imported by 0 modules. It imports 0 modules.
Variables
None
Functions
4.1 dba:db-download
Arities: dba:db-download#2R
dba:db-download
(
$name
as
xs:string
, $resource
as
xs:string
)
as
item() +
- name
as
xs:string
database - resource
as
xs:string
resource
item() +
rest response and file content
Invokes 5 functions from 2 modules
- {http://basex.org/modules/db}content-type#2
- {http://basex.org/modules/db}is-raw#2
- {http://basex.org/modules/db}open#2
- {http://basex.org/modules/db}retrieve#2
- {http://basex.org/modules/web}response-header#2
Invoked by 0 functions from 0 modules
Annotations
%rest:path | ('/dba/db-download') |
%rest:query-param | ('name','{$name}') |
%rest:query-param | ('resource','{$resource}') |
Source ( 20 lines)
function dba:db-download(
$name as xs:string,
$resource as xs:string
) as item()+ {
try {
web:response-header(
map { 'media-type': db:content-type($name, $resource) },
map { 'Content-Disposition': 'attachment; filename=' || $resource }
),
if(db:is-raw($name, $resource)) then (
db:retrieve($name, $resource)
) else (
db:open($name, $resource)
)
} catch * {
<rest:response>
<http:response status='400' message='{ $err:description }'/>
</rest:response>
}
}
Namespaces
The following namespaces are defined:
Prefix | Uri |
---|---|
dba | dba/databases 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
rest | http://exquery.org/ns/restxq |
Source Code
(:~
: Download resources.
:
: @author Christian Grün, BaseX Team 2005-21, BSD License
:)
module namespace dba = 'dba/databases';
(:~
: Downloads a resource.
: @param $name database
: @param $resource resource
: @param $file file name (ignored)
: @return rest response and file content
:)
declare
%rest:path('/dba/db-download')
%rest:query-param('name', '{$name}')
%rest:query-param('resource', '{$resource}')
function dba:db-download(
$name as xs:string,
$resource as xs:string
) as item()+ {
try {
web:response-header(
map { 'media-type': db:content-type($name, $resource) },
map { 'Content-Disposition': 'attachment; filename=' || $resource }
),
if(db:is-raw($name, $resource)) then (
db:retrieve($name, $resource)
) else (
db:open($name, $resource)
)
} catch * {
<rest:response>
<http:response status='400' message='{ $err:description }'/>
</rest:response>
}
};