[Bug report] fs.getFileForSaving()

bug
filesystem

#1

Hi, I’m trying to use the fs.getFileForSaving() but it doesn’t work!

I’m on win 10 here the sample code:

var fs = require("uxp").storage.localFileSystem;
...
const [file] = await fs.getFileForSaving({ types: [ "txt" ]});
if (!file) {
        return;
}
await file.write("It was a dark and stormy night");

Here the console log errors:

Plugin TypeError: a.lastIndexOf is not a function
    at b.<anonymous> (uxp://uxp-internal/home/ubuntu/jenkins/workspace/Torq/torq-native/torq-2.1-xd-13.0/build/modules_gen/webfs/src/js/webfs_scripts.js:134:2139)
    at new Promise (<anonymous>)
    at b.value (uxp://uxp-internal/home/ubuntu/jenkins/workspace/Torq/torq-native/torq-2.1-xd-13.0/build/modules_gen/webfs/src/js/webfs_scripts.js:134:1868)
    at b.<anonymous> (uxp://uxp-internal/home/ubuntu/jenkins/workspace/Torq/torq-native/torq-2.1-xd-13.0/build/modules_gen/webfs/src/js/webfs_scripts.js:138:1937)
    at new Promise (<anonymous>)
    at b.value (uxp://uxp-internal/home/ubuntu/jenkins/workspace/Torq/torq-native/torq-2.1-xd-13.0/build/modules_gen/webfs/src/js/webfs_scripts.js:138:1753)
    at blueRectangle (\main.js:41:29)
    at Object.execScenegraphEdit (plugins/ScenegraphGuard.js:1:2219)
    at BaseCommand._invokePluginCommand [as _commandFn] (plugins/PluginLoader.js:1:2980)
    at BaseCommand.execute (lib/BaseCommand.js:1:929)

I just copied and pasted the sample code from the official doc.

UPDATE: it doesn’t work either on mac os…


#2

We’re in the process of updating the docs here – please try:

const file = await fs.getFileForSaving("yourFile.txt", {types: ["txt"]});

#3

For reference, this is due to the following breaking change listed in the release notes for the 13.0.11 prerelease build:

  • getFileForOpening() returns a File instead of an array if allowMultiple is false (the default value).

So you no longer need the array destructuring ([file] = ...) if you’re only letting the user pick a single file.