# Downloading and checking resources on the fly

**URL:** <https://discourse.psychopy.org/t/downloading-and-checking-resources-on-the-fly/26256>\
**Category:** Online experiments\
**Created:** [November 30, 2021, 11:33am UTC](https://discourse.psychopy.org/t/downloading-and-checking-resources-on-the-fly/26256 "2021-11-30T11:33:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [November 30, 2021, 11:33am UTC](https://discourse.psychopy.org/t/downloading-and-checking-resources-on-the-fly/26256/1 "2021-11-30T11:33:16Z")

</div>

URL of experiment: [spelling [PsychoPy]](https://run.pavlovia.org/Wake/spelling/)

Description of the problem: I’m writing a spelling test where I want to download each word within the experiment.

Since I’m now using 2021.2.3, I need to use **psychoJS.\_serverManager.prepareResources()** instead of psychoJS.downloadResources();

The following code seems to be working in principle (for the conditions file).

psychoJS.\_serverManager.prepareResources([{name: conditionsFile,path: conditionsFile}]);

If I put

```auto
if(conditionsFile.exists()){
  continueRoutine=false;
}

```

in each Frame I get:

- **TypeError: conditionsFile.exists is not a function**

> [@psychJS.downloadResources is not blocking](https://discourse.psychopy.org/t/psychjs-downloadresources-is-not-blocking/12600/7):
>
> It may be as simple as if(testFile.exists()){ continueRoutine=false; } where testFile is the final file to be downloaded (or the one needed most urgently)

which I assumed had worked for @Mike_Pratte:

> [@Downloading Resources On the Fly](https://discourse.psychopy.org/t/downloading-resources-on-the-fly/26125/4):
>
> Oh no, I believe I spoke too soon: the prepareResources() call does not appear to be blocking. I.e. an attempt to use the resource after calling this function will occasionally error, in cases when the download hasn’t completed before the subsequent call to use the resource. A while back you recommended inserting a test for completed download within the routine, which seems straightforward. But if there is a more appropriate implementation in 2021.2.3 I would be very grateful for any suggestions…

If I try my old code for checking resources:

```auto
try {
psychoJS.serverManager.getResource(conditionsFile);
    continueRoutine = false;
} catch (e) {}

```

I don’t give an error but it doesn’t wait either, leading to:

- **Priya Tamber.xlsx is not available for use (yet), its current status is: “DOWNLOADING”**  
unless I give the routine enough time for it to download.

I tried checking conditionsFile.status but it remains set to “undefined” which must mean I haven’t found the correct way to check it.

How should I be checking resource status?

---

<div class="post-metadata">

**Author:** ![Becca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/becca/32/34260_2.png) [@Becca](https://discourse.psychopy.org/u/Becca)\
**Post date:** [December 2, 2021, 9:55am UTC](https://discourse.psychopy.org/t/downloading-and-checking-resources-on-the-fly/26256/2 "2021-12-02T09:55:38Z")

</div>

Hi There,

I think your syntax is close - here is a demo I used recently which may help [Rebecca / resource\_load\_demo · GitLab](https://gitlab.pavlovia.org/Hirst/resource_load_demo) with the [syntax used to prep the resources](https://gitlab.pavlovia.org/Hirst/resource_load_demo/blob/master/resource-loading-demo.js#L155) I think you m ay just need to add some code to the each frame tab to continuously check if the resource status

Hope this helps!  
Becca
