• Building
  • Access files in the directory of the HTML file after exporting to HTML

Hey all!

So, I'm trying to export a project of mine to Html5. But I encounter the following problem:

In the program I do have a text file, which is used for some configuration, while the program is running. This file needs to stay editable even after compiling resulting that the code needs to access this file.

Now, when compiling as a Windows or Mac application this file can be accessed without any problems but when exporting the project to Html5, it can't access the file.

I tried to solve this issue using HTTPRequest. But as far as I seen, I only can use absolute URLs and not relative URLs to access the file.

Is there a way to use an relative URL path?

I hope my problem was clear enough to understand. If you have any further question I'll answer them as soon as possible.

Thank you in advance.

If you want to write to a file it has to be in user:// that is true for HTML5 as well as for Android or iOS. If you want to deploy an initial "template" of that file then this would be in res:// where you can read it. But as writing is always to user:// you'd have to check both paths on next startup.

I just checked my html app. The Firefox Storage Inspector shows an entry in "Indexed DB" -> "/userfs" -> "FILE_DATA". With an entry for each file in user://

These entries will persist over different sessions but they'll be saved on the user side. And finally the browser/user decides if how long he wants to save the games data.

First of all thank you for your quick response.

But it seems to me that I wasn't clear enough in my first post.

The file is as far as Godot concerned a read only file. The editing of the file is being done by an editor like notepad.

The Html file as well as the text file are uploaded on a server. None of those are on a users PC. The two files should be able to be moved to another directory and still work, despite being saved in a new location on the server.

If I misunderstood your answer I have to apologise I still have to improve my English.

I'm assuming you're looking to implement configs that your server/sys admins could tweak here for a MMO type game. So not client side at all.

In that case the HTML5 export should be irrelevant since that is your client for the user(player). For the games server the user dir is still relevant then, since the server instance(or rather the admin I guess) is the user for the software server. Makes sense?

Basically what @wombatstampede shared is still essentially relevant here. The user dir then would have to be stored on the server locally. But afaik there's no way getting around the user:// space.

But hey, maybe I'm misunderstanding. This could well be a case of the xy problem.

5 days later

@wombatstampede said: You could query such a file from javascript in a custom html file. Or just make your config in javascipt format "var a=1" and include it as a script in a custom html file. Ways to communicate to the "outside" html you‘ll find here: https://docs.godotengine.org/en/3.1/getting_started/workflow/export/exporting_for_web.html?highlight=Javascript

So short update: First of all thank you very much for all the help. I was able to figure it out thanks to the custom HTML export. To summarise it up, while looking up how the custom HTML export is functioning I found out, that after the export to HTML the web assembly cant access files on the server. However, when loading them via the HTML file before starting the engine it works without any problems.

I'd like to thank you again for the help and wish you all a nice day.

a year later

Hi @BaseCrusher

May I know how you manage to load the file via HTML ? is it by using engine.preloadFile ?