Saving FilesPremium
Use saveAs whenever your application generates file content in the browser and needs to deliver it to the user without a round-trip to the server. To trigger a download of a file already hosted on a server, use the native HTML download attribute on an anchor element instead.
The function triggers a file download on the client machine. It accepts a data URI or a Blob and a file name.
An optional SaveOptions object lets you route downloads through a server proxy. This approach is recommended for large files or environments that restrict client-side saves.
import { saveAs, encodeBase64 } from '@progress/kendo-file-saver';
const notes = "Meeting notes";
const dataURI = "data:text/plain;base64," + encodeBase64(notes);
saveAs(dataURI, "meeting_notes.txt");
The following demo shows how to save a simple text file generated in the browser.
Saving a Blob
The saveAs function also accepts a Blob directly, which skips the base64 encoding step entirely and is often simpler when the content is already in memory, whether as a string or as raw bytes.
Saving a Blob through a server proxy is not supported. When a proxy is involved, build a data URI instead—see Saving Binary Data for the data URI equivalent of binary content.
import { saveAs } from '@progress/kendo-file-saver';
const content = new Blob(["line 1\nline 2\n"], { type: "text/plain" });
saveAs(content, "report.txt");
The following demo generates a daily sales summary in memory and saves it as a text file from a Blob.
Saving XML Content
Save XML content either as a Blob or as a base64 data URI built with encodeBase64.
Both approaches produce an identical .xml file—choose the Blob when you already have a Blob-producing API (for example, an XML serializer), and the data URI when a server proxy is involved.
import { saveAs, encodeBase64 } from '@progress/kendo-file-saver';
const xml = '<order id="10248"><customer>Café Alfreds</customer></order>';
const xmlBlob = new Blob([xml], { type: "application/xml" });
saveAs(xmlBlob, "order-10248.xml");The following demo shows how to save XML content generated in the browser.
Saving Binary Data
Use a base64 data URI instead of a Blob for binary formats such as PDF or XLSX when a server proxy is involved, since saving a Blob through a proxy is not supported. The encodeBase64 function only accepts strings, so encode raw bytes with the built-in btoa function instead:
import { saveAs } from '@progress/kendo-file-saver';
// pdfBytes is a Uint8Array produced by a PDF generation library
const base64 = btoa(Array.from(pdfBytes, b => String.fromCharCode(b)).join(''));
const dataURI = "data:application/pdf;base64," + base64;
saveAs(dataURI, "document.pdf");
The following demo shows how to save a PDF file generated in the browser.