downloadBytes(data, filename, [preview]) Last updated: 30. May 2026
API only function
A method to trigger a file download from byte data or a base64 encoded string.
Parameters
| Name | Type | Description |
|---|---|---|
| data | base64 | byte[] | The file data to be downloaded, which can be in base64 format or a byte array. |
| filename | string | Filename to download. |
| preview (optional) | bool | Default false, returns a preview and not a download. Meaning it will show / preview in the browser. |
Returns
Starts a file download immediately in the API call and aborts further execution of code in the script.
Example
Code example (JS)
JS is normal JavaScript either running in the browser or on the Docly™ server.() => {
// Download arbitrary byte/text data as a file
let data = docly.textEncode("Some test data");
return docly.downloadBytes(data, 'example.txt', false);
}