How to save a file?

I want to realize a function of saving files. This is the code, but it won’t work. How can I make it work?

async function Test() {

    var p = "C:/Users/abc/Desktop/";

    localStorage.setItem("DP",p)

    // console.log(localStorage.getItem("DP"));

    const thePersistentFolderToken = localStorage.getItem("DP");

    const thePersistentFolder = await fs.getEntryForPersistentToken(thePersistentFolderToken);

    // console.log(p);

    const theNewFile = await thePersistentFolder.createFile("export.psd", {

        overwrite: true

    });

    console.log(theNewFile);

    const saveFile = await fs.createSessionToken(theNewFile);

    CUSTOM.AP([{

        "_obj": "save",

        "as": {

            "_obj": "photoshop35Format"

        },

        "in": {

            "_path": saveFile,

            "_kind": "local"

        },

        "documentID": app.activeDocument._id,

        "saveStage": {

            "_enum": "saveStageType",

            "_value": "saveBegin"

        },

        "_isCommand": false

    }])

}

After a whole day of study and research, I finally understood that uxp cannot silently save files in any location, but only allows users to choose.

1 Like