Hey there!
The UXP APIs, at the moment, don’t allow for “arbitrary file access”. That means that if you want to save to a location that doesn’t have such access by default (the plugin’s data folder would be one such example), you have to get the user’s permission to write into that folder by using the fs.getFolder()
, which opens a folder picker dialog (alternatively, you could also let the user pick a specific file using getFileForSaving
).
But you can use the desktop domain as initialDomain
in the options using something like this (which makes the desktop folder the default folder in the file picker):
const storage = require('uxp').storage;
const fs = storage.localFileSystem;
const desktopDomain = storage.domains.userDesktop;
const folder = await fs.getFolder({initialDomain: desktopDomain});
// folder is now a Folder object
Then, you can use folder
like any other Folder
object (cf. Folder
API Reference).
You can also create a persistent token using fs.createPersistentToken(folder)
and save that token, e.g., to localStorage
to re-use that folder the next time the user uses the plugin without having to re-ask the user for a location.
I hope this helps