File System Access API
File System Access API – access to the user's file system
File System Access API allows web applications to read and write files to the user's device file system with user permission. This opens new possibilities, giving web applications the same power as desktop applications.
The API works only in secure environments (HTTPS or localhost) and requires active user involvement through file or directory selection.
const [fileHandle] = await window.showOpenFilePicker();
const file = await fileHandle.getFile();
const contents = await file.text();
console.log(contents);
In this example: the user selects a file, and we read its contents as text.
const handle = await window.showSaveFilePicker({
suggestedName: 'example.txt',
});
const writable = await handle.createWritable();
await writable.write('Hello world');
await writable.close();
In this example: we create a new file or overwrite an existing one by writing text to it.
File System Access API redefines the capabilities of web applications by enabling real file system access. While there are some limitations and browser support issues, it's very useful for modern web apps aiming to provide desktop-like experiences.