Can a WebGL Unity game run a local process to open an archive?

I have to open an archive in a WebGL project, it is in my computer. Do I have to put it on the localserver? Or it is necessary to use a web socket.

A WebGL app has no access to the file system. With exceptions: you can hack in a Win32 OpenFileDialog but it’ll only work on Windows and the user has to pick the correct file.

In all other cases you need to download external files through a server, typically a web request. While you could make your computer open to the Internet, it’s a security risk, requires port forwarding, and download speed for users will be limited to your upload speed at best.

1 Like

I’m using File.ReadAllText(Application.dataPath + @“/Scripts/jsonFile.json”);. It is in the project files, the user doesn’t have to upload the file. But it seems like when exported to WebGL the file isn’t read. Do I have to open it in a different way?

The File API on WebGL maps to the sandbox file store of the browser app. The file simply won‘t be there in a build because dataPath is probably within that sandbox area, not the system‘s dataPath (eg AppData folder).

Instead you need to place the file in either a Resources folder and use Resources.Load or put it in StreamingAssets so that the file is part of the build.

  1. unity webgl can run a process by using url scheme
  2. unity webgl can open a local file by using html input file
1 Like