# 'uxp' is not defined

**URL:** https://forums.creativeclouddeveloper.com/t/uxp-is-not-defined/1575
**Category:** UXP Plugin API
**Tags:** feature-request, javascript
**Created:** [January 31, 2020, 9:45am UTC](https://forums.creativeclouddeveloper.com/t/uxp-is-not-defined/1575 "2020-01-31T09:45:26Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![yyrcorp](https://avatars.discourse-cdn.com/v4/letter/y/3da27b/32.png) [@yyrcorp](https://forums.creativeclouddeveloper.com/u/yyrcorp)
#### Post date: [January 31, 2020, 9:45am UTC](https://forums.creativeclouddeveloper.com/t/uxp-is-not-defined/1575/1 "2020-01-31T09:45:26Z")

</div>

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

---

<div class="post-metadata">

### Author: ![pklaschka](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/pklaschka/32/3162_2.png) [@pklaschka](https://forums.creativeclouddeveloper.com/u/pklaschka)
#### Post date: [January 31, 2020, 9:51am UTC](https://forums.creativeclouddeveloper.com/t/uxp-is-not-defined/1575/2 "2020-01-31T09:51:15Z")

</div>

Did you import `uxp` with something like `const uxp = require('uxp');`?

PS: Welcome to the forums 👋🙂

---

<div class="post-metadata">

### Author: ![yyrcorp](https://avatars.discourse-cdn.com/v4/letter/y/3da27b/32.png) [@yyrcorp](https://forums.creativeclouddeveloper.com/u/yyrcorp)
#### Post date: [January 31, 2020, 9:52am UTC](https://forums.creativeclouddeveloper.com/t/uxp-is-not-defined/1575/3 "2020-01-31T09:52:58Z")

</div>

No, I didn’t know about that. It worked after importing that. Thank you so much.

---

<div class="post-metadata">

### Author: ![pklaschka](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/pklaschka/32/3162_2.png) [@pklaschka](https://forums.creativeclouddeveloper.com/u/pklaschka)
#### Post date: [January 31, 2020, 9:54am UTC](https://forums.creativeclouddeveloper.com/t/uxp-is-not-defined/1575/4 "2020-01-31T09:54:59Z")

</div>

> [@yyrcorp](#):
>
> format: uxp.formats.binary

I do, however, tend to believe (on second glance) that

```auto
format: uxp.formats.binary

```

should actually either be

```auto
format: uxp.storage.formats.binary

```

or

```auto
format: fs.formats.binary

```

(since you appear to already have imported a variable `fs` from `uxp`)

The fact that it already works is, shall we say, surprising or a rather happy coincidence 😉
