How to download files from the internet using gdscript?

:bust_in_silhouette: Reply From: Wakatta

You need nothing more than to make an HTTPRequest

Example

func download(link, path):
    var http = HTTPRequest.new()
    add_child(http)
    http.connect("request_completed", self, "_http_request_completed")
    http.set_download_file(path)
    var request = http.request(link)
    if request != OK:
        push_error("Http request error")

func _http_request_completed(result, _response_code, _headers, _body):
    if result != OK:
        push_error("Download Failed")
    remove_child($HTTPRequest)

func _ready():
    download("https://godotengine.org/themes/godotengine/assets/logo.svg", "Logo.svg")
2 Likes