How to use the default function from file-saver
Find comprehensive JavaScript file-saver.default code examples handpicked from public code repositorys.
file-saver.default is a module that allows users to save files directly in the browser, without the need for a server, by triggering a file download prompt.
117 118 119 120 121 122 123 124 125 126
} } /* istanbul ignore next */ function downloadFile(fileName, contentType, base64) { const blob = base64toBlob(base64, contentType); file_saver_1.default.saveAs(blob, fileName); } /* istanbul ignore next */ function base64toBlob(base64Data, contentType) { contentType = contentType || '';
21
126
4
+ 8 other calls in file
How does file-saver.default work?
file-saver is a library that provides a way to save files from the browser to the local file system, and the default property is a function that takes a Blob or a File and saves it to the local file system using the saveAs method. The saveAs method uses the FileSaver.js library to save the file with the specified filename. The library also supports several options for the file type and encoding.
Ai Example
1 2 3 4 5
import { saveAs } from "file-saver"; const myObj = { name: "John", age: 30 }; const blob = new Blob([JSON.stringify(myObj)], { type: "application/json" }); saveAs(blob, "myObj.json");
In this example, saveAs is a function imported from file-saver, and is used to save a Blob object containing a JSON representation of the myObj object. The filename of the saved file is specified as the second argument to saveAs.
file-saver.saveAs is the most popular function in file-saver (57 examples)