Hi, im working on an uxp plugin, sadly im struggling with the saving part. It is a batch automation plug in, where multiple images get opened from a folder, processed and then they should be saved one after the other in the output folder, but no image gets saved and instead i get invalid file token.
Tried some different approaches with batch play, saveAs, save, but nothing worked yet.
save function:
async function saveProcessedDocument(doc, originalFile, outputFolder) {
const baseName = originalFile.name.replace(/.[^/.]+$/, “”);
const outputFormatElem = document.getElementById(‘outputFormat’);
const format = outputFormatElem ? outputFormatElem.value : ‘jpg’;
let extension, saveDescriptor;
switch (format) {
case ‘jpg’:
extension = ‘.jpg’;
saveDescriptor = {
_obj: “JPEG”,
extendedQuality: 12, // or whatever quality you prefer
matteColor: { _enum: “matteColor”, _value: “none” }
};
break;
default:
extension = ‘.jpg’;
saveDescriptor = {
_obj: “JPEG”,
extendedQuality: 12,
matteColor: { _enum: “matteColor”, _value: “none” }
};
}
const outputFileName = `${baseName}_processed${extension}`;
const outputPath = outputFolder.nativePath.replace(/\\/g, "/") + "/" + outputFileName;
log(`[DEBUG] Output path string sent: ${outputPath} (type: ${typeof outputPath})`);
try {
const saveAction = {
_obj: "saveAs",
as: saveDescriptor,
in: { _path: outputPath, _kind: "local" }
};
await app.batchPlay([saveAction], {});
log(`Saved successfully: ${outputFileName}`);
} catch (err) {
log(`[SAVE] ERROR saving file: ${outputFileName}`);
log(`[SAVE] ERROR object: ${JSON.stringify(err)}`);
log(`[SAVE] ERROR (stack): ${err.stack || "no stack"}`);
}
}
maybe i have something fundamentally wrong, i appreciate any help and thank you