Is it possible to read files in the Work directory from JavaScript?

I’m currently investigating building an in game panel which interfaces with an
in-proc wasm module and as part of this have a reasonable amount of local user
data (potentially a few KB) to read on the HTML/JS side. Is it possible to
read files saved in the work folder from JavaScript to save me sending this in
tiny chunks over L-Vars? If it isn’t possible right now, could this be
supported in the future?

I haven’t tried file access in javascript with the sim yet, so just a shot in
the dark:

      1. let rawFile = new XMLHttpRequest();
  2."GET", "\work\filename.txt", true);
  3. rawFile.onreadystatechange = function() {
  4.   if (rawFile.readyState === 4) {
  5.     this.allText = rawFile.responseText;
  6.   }
  7. }

You also need to call rawFile.send() after building the request, but
unfortunately that results in the following error:

      1. [Error] Failed to load resource: the server responded with a status of 404 (Unable to process resource request) (work\test.json, line 0)

For what it’s worth, the code snippet you provided is essentially what
Utils.loadFile does internally. I tried a few different variants of the path
with no success:

      1. /work/test.json        (404)
  2. ./work/test.json       (404)
  3. coui://work/test.json  (Cross origin request error)
  4. work://test.json       (Cross origin request error)

Just to add for the benefit of others, this method works perfectly fine for
files that are embedded in the package, but files written to the work folder
from a wasm module can’t be read in this way unless there’s another path/API
that I haven’t found yet.

Hello Steve, As you mentioned in your last comments, only files embedded in
the package can be accessed through js at the moment. I’ve added a task about
giving access to the work directory in our backlog. I suggest you create an
idea about this feature so people can upvote it and we have a better idea of
how to prioritize it. Regards, Sylvain

necro alert, apologies - “this method works perfectly fine for files that are
embedded in the package” - is that correct? In my JS I’m trying to READ files
in the SimObject directory of my package and as far as I can tell Coherent is
treating the “html_UI” package directory as the root of the http access, so
there’s no access in JS outside of that directory (I’ve tried
“/…/SimObjects/…” but no success).

In JS you can access the entire VFS, which includes your package content
(except where it may conflict with another package).