I was trying to write a temporary file on disk, but in the downloadImage function ,I got that error.
“uxp is not defined”.
function xhrBinary(url) { // [1]
return new Promise((resolve, reject) => { // [2]
const req = new XMLHttpRequest(); // [3]
req.onload = () => {
if (req.status === 200) {
try {
const arr = new Uint8Array(req.response); // [4]
resolve(arr); // [5]
} catch (err) {
reject(`Couldnt parse response. ${err.message}, ${req.response}`);
}
} else {
reject(`Request had an error: ${req.status}`);
}
}
req.onerror = reject;
req.onabort = reject;
req.open('GET', url, true);
req.responseType = "arraybuffer"; // [6]
req.send();
});
}
function applyImagefill(selection, file) { // [1]
const imageFill = new ImageFill(file); // [2]
selection.items[0].fill = imageFill; // [3]
}
async function downloadImage(selection, jsonResponse) {
try {
const photoUrl = jsonResponse.message; // [2]
const photoObj = await xhrBinary(photoUrl); // [3]
const tempFolder = await fs.getTemporaryFolder(); // [4]
const tempFile = await tempFolder.createFile("tmp", { overwrite: true }); // [5]
await tempFile.write(photoObj, { format: uxp.formats.binary }); // [6]
applyImagefill(selection, tempFile); // [7]
} catch (err) {
console.log("error")
console.log(err.message);
}
}
Is there anything I missed to add? Thank you for your support