Function API only Updated 22 Oct 2026
downloadBytes(data, filename, [preview])
A method to trigger a file download from byte data or a base64 encoded string.
Parameters
database64 | byte[]requiredThe file data to be downloaded, which can be in base64 format or a byte array.
filenamestringrequiredFilename to download.
previewbooloptionalDefault 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 string. A string that is not valid base64 throws.
Example
Normal JavaScript, 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);
}