Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UXP: document saveAs method is not saving the document as a jpeg/png #350

Open
gunjanbangde opened this issue Nov 9, 2022 · 0 comments
Open

Comments

@gunjanbangde
Copy link

Hi, we are trying to save the current document as jpeg/png in the temp folder and then read it as an ArrayBuffer for sending it on the API. Here is our code:

  const app = require("photoshop").app;
  const fs = await require("uxp").storage.localFileSystem;
  const formats = require("uxp").storage.formats;
  const currentDocument = app.activeDocument;
  const tempFolder = await fs.getTemporaryFolder();
  const file = await tempFolder.createFile("test.jpg", { overwrite: true });
  console.log(file, "fileToken");
  currentDocument.saveAs.jpg(
        file,
        {
          quality: 7,
        },
        true
      );
   const arrayBuffer = await file.read({ format: formats.binary });
   console.log(arrayBuffer, "arrayBuffer");

We have tried this without the temp folder too. Code for that:

  const app = require("photoshop").app;
  const fs = await require("uxp").storage.localFileSystem;
  const formats = require("uxp").storage.formats;
  const currentDocument = app.activeDocument;
  const file = await fs.getFileForSaving("test.jpg");
  console.log(file, "fileToken");
  currentDocument.saveAs.jpg(
        file,
        {
          quality: 7,
        },
        true
      );
   const arrayBuffer = await file.read({ format: formats.binary });
   console.log(arrayBuffer, "arrayBuffer");

But the issue is that the saveAs.jpg method doesn’t save the file at all. The file token is also generated correctly in both the cases. Just the saveAs method doesn’t create a file on the system.

Our manifest config:

 "version": "1.0.0",
  "main": "index.html",
  "manifestVersion": 4,
  "host": {
    "app": "PS",
    "minVersion": "23.0.0",
    "data": {
      "apiVersion": 2,
      "loadEvent": "use"
    }
  },
   "requiredPermissions": {
    "allowCodeGenerationFromStrings": true,
    "localFileSystem": "fullAccess"
  }

App versions that we are using:
Photoshop: 24.0
UXP dev tools: 1.7.0

Please let me know if you require any more details for the solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant