I would like to know if there is possibility to download file from Sanity with HTTP request?
I only have reference ID:
{
file: {
asset: {
_ref: "file-fxxxxxxxxxxxxxxxxxxxx-xlsx"
_type: "reference"
}
}
}
I would like to do this is this scenario:
<a href="https://cdn.sanity.io/assets/clientID/dataset/file-xxxxxxxxxxx-xlsx">
Download File
</a>
You can, indeed With a bit of custom code you can do it just from the
_ref
, which is the file document's_id
Creating the URL from the
_ref
/_id
of the fileThe
_ref
/_id
structure is something like this:file-{ID}-{EXTENSION}
(example:file-207fd9951e759130053d37cf0a558ffe84ddd1c9-mp3
).With this, you can generate the downloadable URL, which has the following structure:
https://cdn.sanity.io/files/{PROJECT_ID}/{DATASET}/{ID_OF_FILE}.{EXTENSION}
. Here's some pseudo Javascript code for the operation:Querying the URL directly
However, if you can query for the file's document with GROQ that'd be easier:
You can do the same with images, too.