Skip to content

Instantly share code, notes, and snippets.

@bhaskar-nair2
Created January 8, 2021 03:15
Show Gist options
  • Save bhaskar-nair2/61eaacd610735b24cca88c4f1e52cf84 to your computer and use it in GitHub Desktop.
Save bhaskar-nair2/61eaacd610735b24cca88c4f1e52cf84 to your computer and use it in GitHub Desktop.
// Get File
const getFileBtn = document.getElementById("fs-get")
getFileBtn.onclick = async () => {
const [handle] = await window.showOpenFilePicker();
const file = await handle.getFile();
console.log(file)
}
// Save File
const saveFileBtn = document.getElementById("fs-save")
saveFileBtn.onclick = async () => {
const textFile = new File(["Hello World"], hello.text, {
type: "text/plain"
})
const handle = window.showSaveFilePicker();
const writeable = await handle.createWritable();
await writeable.write(textFile);
await writeable.close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment