Download a .zip file from the internet

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By SF123

I am making a game launcher program for my multiple games and just got to the part where I need to download the .zip file and extract it. It would be lovely it someone could get back to me on this, since I am fairly new at GDScript, and have tried multiple things, none of which have worked.

If at all possible, I would like to be also, one done extracting the .zip file, delete it.

Thanks in advance.

:bust_in_silhouette: Reply From: droc101

You can download the file with an HTTPRequest node (code below) but as far as I know, you cannot extract archive files.

You can however load .pck files at runtime (godot’s file format for storing the res:// filesystem at export.) You can choose what files you place in the PCK per export preset. This could be used to somehow load a small game, or you could download this and a .exe to launch the game separate (I do this for a similar project to yours.)

Download a file with HTTPRequest (put this code in a HTTPRequest’s script):

func download(url : String, target : String):
    download_file = target # where to save the downloaded file
    request(url) # start the download

HTTPRequest has a signal that it emits when the download completes, you can use that to do something with the file, then delete it.

You can also delete files using the Directory class’s remove(path) function

Thank you very much. I had seen the download file but I did not want to touch it and break everything.

This helped very much and may have just saved my launcher!

Thank you SO much!

SF123 | 2021-02-25 22:26

Thanks! At the beggining I was thinking this doesn’t work but it was because I forgot writting the file name and the extension with the “/” in the path.

Dani Ximple Apps | 2021-05-03 20:00

:bust_in_silhouette: Reply From: deaton64

Does this help?