Can I get image file from the server - Like in Game Maker : http_get_file ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By yalondpsi
:warning: Old Version Published before Godot 3 was released.

Hi
I want to download dynamically an image from the server and than load it into the game
Is it doable in Godot?
Thanks
Yalon

:bust_in_silhouette: Reply From: ingo_nikot

you can download the content of files via the HTTPClient class.

here is an example:
http://codetuto.com/2015/05/using-httpclient-in-godot/

:bust_in_silhouette: Reply From: Zylann

I had a try with a different method, there is a specialized function to choose where to put the file. I created a button for testing and an HTTPRequest node as child of it.
Then I added this script on the button:

extends Button


onready var _request = get_node("HTTPRequest")


func _ready():
	connect("pressed", self, "_on_button_pressed")
	_request.connect("request_completed", self, "_on_request_completed")


func _on_button_pressed():
	print("Doing request...")
	_request.set_download_file("the_thing.png")
	_request.request("http://docs.godotengine.org/en/stable/_static/docs_logo.png")


func _on_request_completed(result, response_code, headers, body):
	print("Request completed ", result, ", ", response_code)
	

However the file arrived partially corrupted, with the following error:

ERROR: DVector<unsigned char>::resize: Condition ' mem.is_locked() ' is true. returned: ERR_LOCKED
At: c:\projects\godot-builds\godot\core\dvector.h:365

enter image description here

When I did it none of the files I tried got corrupted at all.

toivocat | 2021-12-30 18:39

:bust_in_silhouette: Reply From: yalondpsi

Thank you, I will check it