# How can I import an image or a file in Batchplay?

**URL:** https://forums.creativeclouddeveloper.com/t/how-can-i-import-an-image-or-a-file-in-batchplay/3977
**Category:** UXP Plugin API
**Created:** [December 4, 2021, 9:55am UTC](https://forums.creativeclouddeveloper.com/t/how-can-i-import-an-image-or-a-file-in-batchplay/3977 "2021-12-04T09:55:15Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ttvrac](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/ttvrac/32/1823_2.png) [@ttvrac](https://forums.creativeclouddeveloper.com/u/ttvrac)
#### Post date: [December 4, 2021, 9:55am UTC](https://forums.creativeclouddeveloper.com/t/how-can-i-import-an-image-or-a-file-in-batchplay/3977/1 "2021-12-04T09:55:15Z")

</div>

Hello,  
How can I import an image or a file in Batchplay? I want to import a file available locally in the plugin folder to the open project in Photoshop.  
I started with this but it doesn’t work …

const batchPlay = require(“photoshop”).action.batchPlay;  
async function Import() {  
const result = await batchPlay(  
[  
{  
\_obj: “placeEvent”,  
ID: 1671,  
null: {  
\_path: “C:\Users\me\Downloads\MyPlugin\White.png”,  
\_kind: “local”  
},  
freeTransformCenterState: {  
\_enum: “quadCenterState”,  
\_value: “QCSAverage”  
},  
offset: {  
\_obj: “offset”,  
horizontal: {  
\_unit: “pixelsUnit”,  
\_value: 0  
},  
vertical: {  
\_unit: “pixelsUnit”,  
\_value: 0  
}  
},  
\_options: {  
dialogOptions: “dontDisplay”  
}  
}  
],{  
synchronousExecution: false,  
modalBehavior: “fail”  
});  
}

Thank you in advance for your answers

---

<div class="post-metadata">

### Author: ![simonhenke](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/simonhenke/32/957_2.png) [@simonhenke](https://forums.creativeclouddeveloper.com/u/simonhenke)
#### Post date: [December 4, 2021, 2:38pm UTC](https://forums.creativeclouddeveloper.com/t/how-can-i-import-an-image-or-a-file-in-batchplay/3977/2 "2021-12-04T14:38:26Z")

</div>

> [@ttvrac](#):
>
> \_path: “C:\Users\me\Downloads\MyPlugin\White.png”,

Accessing files via paths won’t work in UXP. For security reasons, you need to create a token of that file entry first (check the docs) and pass that one to the `_path` key

---

<div class="post-metadata">

### Author: ![DrPepperJo](https://avatars.discourse-cdn.com/v4/letter/d/0ea827/32.png) [@DrPepperJo](https://forums.creativeclouddeveloper.com/u/DrPepperJo)
#### Post date: [December 5, 2021, 2:01am UTC](https://forums.creativeclouddeveloper.com/t/how-can-i-import-an-image-or-a-file-in-batchplay/3977/3 "2021-12-05T02:01:58Z")

</div>

UXP requires the user to manually allow access to the file you want to import. That can either be done directly by letting the user select the file:

> const fs = require(‘uxp’).storage.localFileSystem;

> const file = await fs.getFileForOpening()

or, if you want to have your program select the file(s), by selecting a directory tree containing said file(s):

> const folder = await fs.getFolder()

To get all the files on the selected level you could do something like that:

> const entries = await folder.getEntries();  
> const files = entries.filter( entry =\> entry.isFile );

To be able to provide a string to set for the path:

> \_path: “C:\Users\me\Downloads\MyPlugin\White.png”,

you can create a token for the file in question:

> const token = fs.createSessionToken( file );

and replace the above line by:

> \_path: token

---

<div class="post-metadata">

### Author: ![ttvrac](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/ttvrac/32/1823_2.png) [@ttvrac](https://forums.creativeclouddeveloper.com/u/ttvrac)
#### Post date: [December 5, 2021, 10:29am UTC](https://forums.creativeclouddeveloper.com/t/how-can-i-import-an-image-or-a-file-in-batchplay/3977/4 "2021-12-05T10:29:28Z")

</div>

Thanks a lot ! It helped me so much
