downloadBytes(data, filename, [preview]) Last updated: 17. Oct 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 the file download and stops the script. The Content-Type comes from the filename's extension.

Returns null when data is null or the filename is empty, and an error text when data is not a byte array, an array of numbers or a base64 string.

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);    
}