05 api.writeFile(path, base64)

  // UTF-8-safe text -> base64 (plain btoa() throws on non-Latin-1 characters)
  function b64(text) {
    const bytes = new TextEncoder().encode(text);
    let bin = '';
    for (const b of bytes) bin += String.fromCharCode(b);
    return btoa(bin);
  }
  
  await api.writeFile(api.dir + '/config.json', b64(JSON.stringify({ server: 'https://x' })));

- Max 256 KB. Empty content is rejected (400 empty body), so to "clear" a JSON file write {}.
- Absolute path, no ... Parent folders are created. Atomic: written to path.tmp, then swapped in.
- Sent as multipart, so binary data (NUL bytes) survives.
- Not limited to your own folder. Any path except the credential stores works, but keep your data in api.dir.
‹ PreviousReader file (.txt)Next ›