# Export JPEG and get file size in UXP

**URL:** <https://forums.creativeclouddeveloper.com/t/export-jpeg-and-get-file-size-in-uxp/2992>\
**Category:** UXP Plugin API\
**Created:** [May 26, 2021, 4:10am UTC](https://forums.creativeclouddeveloper.com/t/export-jpeg-and-get-file-size-in-uxp/2992 "2021-05-26T04:10:08Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![rascheln](https://avatars.discourse-cdn.com/v4/letter/r/e19b73/32.png) [@rascheln](https://forums.creativeclouddeveloper.com/u/rascheln)\
**Post date:** [February 3, 2023, 9:48pm UTC](https://forums.creativeclouddeveloper.com/t/export-jpeg-and-get-file-size-in-uxp/2992/21 "2023-02-03T21:48:32Z")

</div>

Is there any further information on this? Is there any way to export a file using UXP? I can confirm that the Alchemist plugin, even the development version I installed via the UXP Developer Tool, returns zero events for any file export.

This seems like it should be _utterly basic_ functionality.

---

<div class="post-metadata">

**Author:** ![Maher](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/maher/32/1432_2.png) [@Maher](https://forums.creativeclouddeveloper.com/u/Maher)\
**Post date:** [February 4, 2023, 2:37am UTC](https://forums.creativeclouddeveloper.com/t/export-jpeg-and-get-file-size-in-uxp/2992/22 "2023-02-04T02:37:51Z")

</div>

I ended up using legacy export, which can be recorded by actions/Alchemist

I remember seeing export in the road map under (far future) more than a year ago I think

I also read somewhere in the forums that export functionality is available to be used under the hood, I just didn’t manage to figure out the parameters since it’s private and undocumented

TLDR: not available yet  
you can record legacy export  
you can use quick export which only allows choosing the target folder but not the filename

---

<div class="post-metadata">

**Author:** ![sttk3](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sttk3](https://forums.creativeclouddeveloper.com/u/sttk3)\
**Post date:** [February 4, 2023, 5:19am UTC](https://forums.creativeclouddeveloper.com/t/export-jpeg-and-get-file-size-in-uxp/2992/23 "2023-02-04T05:19:50Z")

</div>

Can the “export” you are talking about be substituted with “saveAs”?

Here’s an example

- [UXP: document saveAs method is not saving the document as a jpeg/png](http://forums.creativeclouddeveloper.com/t/uxp-document-saveas-method-is-not-saving-the-document-as-a-jpeg-png/5471)

### Document about saveAs

- [https://developer.adobe.com/photoshop/uxp/2022/ps\_reference/classes/document/#saveas](https://developer.adobe.com/photoshop/uxp/2022/ps_reference/classes/document/#saveas)

### Document about save options

- [BMP Save Options](https://developer.adobe.com/photoshop/uxp/2022/ps_reference/objects/saveoptions/bmpsaveoptions/)
- [GIF Save Options](https://developer.adobe.com/photoshop/uxp/2022/ps_reference/objects/saveoptions/gifsaveoptions/)
- [JPEG Save Options](https://developer.adobe.com/photoshop/uxp/2022/ps_reference/objects/saveoptions/jpegsaveoptions/)
- [PNG Save Options](https://developer.adobe.com/photoshop/uxp/2022/ps_reference/objects/saveoptions/pngsaveoptions/)
- [Photoshop Save Options](https://developer.adobe.com/photoshop/uxp/2022/ps_reference/objects/saveoptions/photoshopsaveoptions/)

---

<div class="post-metadata">

**Author:** ![rascheln](https://avatars.discourse-cdn.com/v4/letter/r/e19b73/32.png) [@rascheln](https://forums.creativeclouddeveloper.com/u/rascheln)\
**Post date:** [February 4, 2023, 6:42am UTC](https://forums.creativeclouddeveloper.com/t/export-jpeg-and-get-file-size-in-uxp/2992/24 "2023-02-04T06:42:22Z")

</div>

It cannot, because I need to be able to downscale on exporting. I do wish that I could use it, though!

@Maher Thanks so much for this suggestion! This looks very promising, though, I must admit, this is one of the more confusing event descriptors I’ve come across. Would you happen to have any further information on what the legacy export parameters mean?

---

<div class="post-metadata">

**Author:** ![Maher](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/maher/32/1432_2.png) [@Maher](https://forums.creativeclouddeveloper.com/u/Maher)\
**Post date:** [February 4, 2023, 10:47am UTC](https://forums.creativeclouddeveloper.com/t/export-jpeg-and-get-file-size-in-uxp/2992/25 "2023-02-04T10:47:19Z")

</div>

property names are a mess, for my case I used known value in the properties I want to be dynamic and looked for that value and replaced it with my own variables.

```auto
async function quickExport(folder, filename, quality) {
   await executeAsModal(async () => {
      let command = { "_obj": "export", "using": { "$DIDr": true, "$EICC": false, "$Mtt": false, "$MttB": 255, "$MttG": 255, "$MttR": 255, "$Op": { "_enum": "$SWOp", "_value": "$OpSa" }, "$Pass": 1, "$QCUI": 0, "$QChS": 0, "$QChT": false, "$QChV": false, "$SHTM": false, "$SImg": true, "$SWch": { "_enum": "$STch", "_value": "$CHsR" }, "$SWmd": { "_enum": "$STmd", "_value": "$MDCC" }, "$SWsl": { "_enum": "$STsl", "_value": "$SLAl" }, "$obCS": { "_enum": "$STcs", "_value": "$CS01" }, "$obIA": false, "$obIP": "", "$ohAA": true, "$ohAC": { "_enum": "$SToc", "_value": "$OC03" }, "$ohCA": false, "$ohEn": { "_enum": "$STen", "_value": "$EN00" }, "$ohIC": true, "$ohIZ": true, "$ohIn": -1, "$ohLE": { "_enum": "$STle", "_value": "$LE03" }, "$ohQA": true, "$ohTC": { "_enum": "$SToc", "_value": "$OC03" }, "$ohXH": false, "$olCS": false, "$olEC": { "_enum": "$STst", "_value": "$ST00" }, "$olNC": [{ "$ncTp": { "_enum": "$STnc", "_value": "$NC00" }, "_obj": "$SCnc" }, { "$ncTp": { "_enum": "$STnc", "_value": "$NC19" }, "_obj": "$SCnc" }, { "$ncTp": { "_enum": "$STnc", "_value": "$NC28" }, "_obj": "$SCnc" }, { "$ncTp": { "_enum": "$STnc", "_value": "$NC24" }, "_obj": "$SCnc" }, { "$ncTp": { "_enum": "$STnc", "_value": "$NC24" }, "_obj": "$SCnc" }, { "$ncTp": { "_enum": "$STnc", "_value": "$NC24" }, "_obj": "$SCnc" }], "$olSH": { "_enum": "$STsp", "_value": "$SP04" }, "$olSV": { "_enum": "$STsp", "_value": "$SP04" }, "$olWH": { "_enum": "$STwh", "_value": "$WH01" }, "$ovCB": true, "$ovCM": false, "$ovCU": true, "$ovCW": true, "$ovFN": filename, "$ovNC": [{ "$ncTp": { "_enum": "$STnc", "_value": "$NC01" }, "_obj": "$SCnc" }, { "$ncTp": { "_enum": "$STnc", "_value": "$NC20" }, "_obj": "$SCnc" }, { "$ncTp": { "_enum": "$STnc", "_value": "$NC02" }, "_obj": "$SCnc" }, { "$ncTp": { "_enum": "$STnc", "_value": "$NC19" }, "_obj": "$SCnc" }, { "$ncTp": { "_enum": "$STnc", "_value": "$NC06" }, "_obj": "$SCnc" }, { "$ncTp": { "_enum": "$STnc", "_value": "$NC24" }, "_obj": "$SCnc" }, { "$ncTp": { "_enum": "$STnc", "_value": "$NC24" }, "_obj": "$SCnc" }, { "$ncTp": { "_enum": "$STnc", "_value": "$NC24" }, "_obj": "$SCnc" }, { "$ncTp": { "_enum": "$STnc", "_value": "$NC22" }, "_obj": "$SCnc" }], "$ovSF": true, "$ovSN": "images", "_obj": "SaveForWeb", "blur": 0.0, "format": { "_enum": "$IRFm", "_value": "JPEG" }, "in": { "_kind": "local", "_path": folder }, "interfaceIconFrameDimmed": false, "optimized": true, "quality": quality } };
      result = await batchPlay([command], {});
   }, { "commandName": "Exporting..." });
}

```

the example above exports JPG using a token, filename and quality

---

<div class="post-metadata">

**Author:** ![rascheln](https://avatars.discourse-cdn.com/v4/letter/r/e19b73/32.png) [@rascheln](https://forums.creativeclouddeveloper.com/u/rascheln)\
**Post date:** [February 6, 2023, 9:14pm UTC](https://forums.creativeclouddeveloper.com/t/export-jpeg-and-get-file-size-in-uxp/2992/26 "2023-02-06T21:14:25Z")

</div>

Oh, very interesting! I’m wondering: when I looked at this command on alchemist, I saw no option for “quality,” so I do not know what that property is supposed to expect. [EDIT] I’m guessing that, since my own goals are to save as PNG24, there is no quality setting that I’d be making.

When I recorded this action with Alchemist and changed the quality setting, I still could not get “quality” to appear. What do I put for quality? In my case, I want to export to a target resolution, so I’m assuming that I need to change `_value` for:

```auto
      "$HScl": {
         "_unit": "percentUnit",
         "_value": 50
      },
      "$VScl": {
         "_unit": "percentUnit",
         "_value": 50
      },

```

Additionally, just to be sure, in your field, you have a `folder` option. ~~Is this the usual method for retrieving a folder for export?~~ [EDIT] the code below is incorrect. See at end of post.

```auto
async function getUserFolderSessionToken() {
  const entry = await fs.getFolder();
  try {
    return entry;
  } catch (e) {
    console.error(e);
  }
};

```

_edit_ I did some more investigation, and I applied the above steps. However, I am getting the following error:

```auto
NAPI API failure: String expected

```

What I did slightly differently was have a separate function for populating the event descriptor, then I assigned that to [batchCommands], then I inserted that into:

```auto
async function exportLegacy(folder, fileName, scalePercent) {
  let batchCommands = [eventExportLegacy(folder, fileName, scalePercent)];
  try {
    return await executeAsModal(async () => {
      /*I get the error here*/await batchPlay(batchCommands, {});
    }, { commandName: "Legacy Export" });
  } catch (e) {
    console.error(e);
  }
};

```

[EDIT]  
This is the code I used for retrieving a session token to feed into the batchplay event descriptor:

```auto
async function getUserFolderSessionToken() {
  let entry = await fs.getFolder();
  let token = fs.createSessionToken(entry);
  console.log(token);
  try {
    return token;
  } catch (e) {
    console.error(e);
  }
};

```

I was missing a step. `fs.GetFolder();` does not retrieve the values needed for writing to a folder. I need that second line `let token = fs.createSessionToken(entry);` to effectively act as the “folder path to write stuff to” [explained here](https://developer.adobe.com/photoshop/uxp/uxp/reference-js/Modules/uxp/Persistent%20File%20Storage/FileSystemProvider/#createsessiontokenentry).

[Previous page](https://forums.creativeclouddeveloper.com/t/export-jpeg-and-get-file-size-in-uxp/2992.md?page=1)
