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.
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.
- unity webgl can run a process by using url scheme
- unity webgl can open a local file by using html input file