• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Help with downloading a file using http_get_file

LDinos

Member
Greetings! I am trying to make a simple auto update checker, and I thought of doing it like this: Download a text file that I have uploaded, read the string inside it, and compare it to the current version string. However I have a problem using http_get_file. Here's the object

Create event:
Code:
file = http_get_file("https://drive.google.com/uc?export=download&id=18TOKTHNzruc92BoK6YGOiQy1rLEqhSAi", working_directory)
The link is a direct download

HTTP event:
Code:
if ds_map_find_value(async_load, "id") == file
    {
    var status = ds_map_find_value(async_load, "status");
    var full_status = ds_map_find_value(async_load,"http_status");
    if status == 0
        {
        var path = ds_map_find_value(async_load, "result");
        var txt = file_text_open_read(path)
            var ver = file_text_read_string(txt)
            show_message(ver + " - " + global.version)
        file_text_close(txt)
        }
    else {str = full_status} //show me the error if status = -1
    }
What happens: Status returns -1 and full_status returns 200! The file is not even downloaded :(
What am I doing wrong?

Using GMS 2.2.4.474
 

FrostyCat

Redemption Seeker
What happens: Status returns -1 and full_status returns 200! The file is not even downloaded :(
What am I doing wrong?
Did you read the example at the bottom of http_get_file()'s Manual entry? The second argument to http_get_file() expects a complete file name, not just a directory name. The HTTP result is 200 because your URL is valid, but the status is -1 because you are trying to overwrite working_directory with the file you downloaded.

This is what you should have done:
Code:
file = http_get_file("https://drive.google.com/uc?export=download&id=18TOKTHNzruc92BoK6YGOiQy1rLEqhSAi", working_directory + "vercheck.txt");
I fixed it by using "http_get" instead!
http_get() is not a complete replacement for http_get_file(). It may work for you at the moment, but the http_get() approach will come apart the instant you download any binary-formatted file that has a 0 byte in it (which terminates strings early). You should learn the right way with http_get_file() going forward.
 

LDinos

Member
Did you read the example at the bottom of http_get_file()'s Manual entry? The second argument to http_get_file() expects a complete file name, not just a directory name. The HTTP result is 200 because your URL is valid, but the status is -1 because you are trying to overwrite working_directory with the file you downloaded.

This is what you should have done:
Code:
file = http_get_file("https://drive.google.com/uc?export=download&id=18TOKTHNzruc92BoK6YGOiQy1rLEqhSAi", working_directory + "vercheck.txt");
http_get() is not a complete replacement for http_get_file(). It may work for you at the moment, but the http_get() approach will come apart the instant you download any binary-formatted file that has a 0 byte in it (which terminates strings early). You should learn the right way with http_get_file() going forward.
Ah, thank you very much, this makes sense
 
Top