Hi, this is my first post here. I have been playing with Godot for a few days now and i am super impressed even if it is a bit over my head. I am building a html5 project and want the user to be able to load files from the local filesystem. I can do this with the following code

extends Control

func _on_Button_pressed():
	var content = JavaScript.eval("""
		var input = document.createElement('input');
		input.type = 'file';

		input.onchange = e => { 
   			var file = e.target.files[0]; 
  			var reader = new FileReader();
   			reader.readAsText(file,'UTF-8');
   			reader.onload = readerEvent => {
	  		var filecontent = readerEvent.target.result; // this is the content!
			}
		}
		input.click();
	""")

My problem is how to get the data in to a variable that godot can use.

Welcome to the forums @orangetek!

I don't know if it would help or not, but have you seen ECMAScript? It's a GDNative binding of the Javascript language to Godot, and it looks like the overwhelming majority of Javascript is accessible, so it is possible that you can get file input in a way Godot can use through ECMAScript.

Thanks, i was hoping for something GDscript related as my JS is poor. I'll take a look

2 years later