Database Reference
In-Depth Information
We examine the URI after calling
request:get-uri
to see if it contains the iden‐
tifier of an image.
We extract the identifier of the image from the URI.
We call the function
local:get-image
with the identifier of the image (
$image-
name
). This function has been omitted for brevity, but all you need to know right
now is that it retrieves an image previously stored into the database; otherwise
(i.e., if there is no image with that identifier in the database), it returns an empty
sequence.
We test if we have an image from the database for the identifier.
We have an image, so we return it in the HTTP response by calling the
response:stream-binary
function.
Otherwise, there was no image in the database matching the identifier, so we set
the response status to
404 Not Found
and return an explanation in the body of
the response.
Retrieve a thumbnail representation of an image from the database.
The API provided by
the
image-api.xq
file allows you to send an HTTP
GET
to it via the REST Server API to
get a thumbnail of a previously stored image. If the URI in your HTTP request
includes an identifier of an image previously stored by the API prefixed by
thumb
nail/
, it will return a thumbnail representation of that image. The
image-api.xq
file
will generate the thumbnail on the fly, store it into the database, and return it; if the
same thumbnail is requested a second time, the API serves it from the database rather
than regenerating it.
To see this in action, make the following request with cURL:
curl http://localhost:8080/exist/rest/db/image-api.xq/
thumbnail/28068cd4-4817-4f81-ae19-5ad2c945186a.jpg
The
thumbnail/
URI segment has been inserted before the identi‐
fier of the image—compare this to the URI used in the previous
section.
The code in our
image-api.xq
file for handling this request is actually very similar to
that for retrieving an image, except for a few minor changes. Therefore, we will only
really examine the differences:
Search WWH ::
Custom Search