Skip to content

Allow open & save to file (window.showOpenFilePicker) #13

@Edwinexd

Description

@Edwinexd

There is a webapi in development that could be used to allow users to open/create a save file once and then repeatedly save to the same file without creating a bunch of dumps in the users download folder
https://developer.mozilla.org/en-US/docs/Web/API/Window/showOpenFilePicker#browser_compatibility

Example generated by Chatgpt:

// Open file
async function openFile() {
  const [fileHandle] = await window.showOpenFilePicker();
  const file = await fileHandle.getFile();
  const contents = await file.text();
  console.log(contents); // Load file contents
  return fileHandle; // Return handle for saving
}

// Save file
async function saveFile(fileHandle, data) {
  const writableStream = await fileHandle.createWritable();
  await writableStream.write(data); // Write new content
  await writableStream.close();
}

Edit: might be more readily available then I initially thought https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions