How to save the image on the same location automatically from where it was opened

Hey, I am kinda new to UXP trying it out last week and I opened an image by dragging and dropping in Photoshop (Note the document is not saved) and when I am running the plugin I save the files after changes as a new PNG image but it is asking for the location to save while I want to automatically save to the location from where the Image file was opened in photoshop.

This is my code :

const exportFileName = ${currentDocument.title.replace(/\.[^/.]+$/, "")}_test.png;
// Export the file from the current document
try {
const saveFile = await fs.getFileForSaving(exportFileName, { types: [“png”] });

  if (saveFile) {
    await currentDocument.saveAs.png(saveFile, {
      quality: 100,
      interlaced: false,
      optimized: true,
      transparency: true
    console.log(`Exported file saved as ${saveFile.nativePath}`);
} catch (error) {
  console.error(`Could not export the file: ${error.message}`);

What should I add or maybe do to put the native location as well in the parameters?
I tried to createfile() as well but it was not working.

Please Help ! Thanks !

You need to retrieve the path of the currently opened document. Unfortunately, fs.getFileForSaving does not support setting the initial path directly. However, you can use the storage APIs to handle file paths and create files directly.

This approach is an old topic, I’ve tried them all, unfortunately it doesn’t seem to be possible. In my case I preferred to save and close the document.

Even I tried Storage APIs and it still didn’t work at all , there must be a way right did anyone tried doing it with Batchplay is it even possible ?

It may possibly be achieved by using getEntryWithUrl to generate an Entry from a path string.

This example gives a good explanation.