HTTPREQUEST get_body size and get_downloaded_byte return -1 and 0

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

I have uploaded some photos on googledrive and use HTTPREQUEST to download them.Then I use get_downloaded_bytes() and get_body_size() to track the progress.

However, when the file exceed 2MB, the body size will always return -1 and downloaded byte returns 0. But it will eventually finish the download and everything seems to work fine afterwards.

Here are the test project:

Click “<2MB” or “>2MB” will start downloading the file to “user://” and after the donwload succeeded, click “Show” will show the photo.

Both will download successfully but the larger file will only show 0%. I print out the body size and downloaded byte in the debug and it shows -1 and 0 in body size and downloaded byte. and when about to finish downloading, the downloadedbyte will show correct number but body size keeps -1. But the smaller file will show the correct number for both.

Here are more test photos:


Just replace the string after “id=” in $HTTPRequest.request(“”)

Below is the code.

extends Node2D

var status = 123
var downloaded_bytes = 123
var body_size = 123
var progress = 123
onready var download_status = get_node("DownloadStatus")

func _ready():

func _process(delta):
    status = $HTTPRequest.get_http_client_status()
    downloaded_bytes = $HTTPRequest.get_downloaded_bytes()
    body_size = $HTTPRequest.get_body_size()
    print("Status: ", status)
    print("Downloadedbytes: ", downloaded_bytes)
    print("BodySize: ", body_size)
    if status == 6 or status == 3 or status == 1:
        download_status.text = "Connecting to Server..."
    elif status == 7:
        progress = (downloaded_bytes * 100 / body_size) 
        download_status.text = str(progress) + " %"
    elif status == 5:
        download_status.text = "Server Connected"
    elif status == 4 or status == 2:
        download_status.text = "Can't connect to the server" 
        download_status.text = "Error"

func _on_HTTPRequest_request_completed( result, response_code, headers, body ):
    download_status.text = "Download Completed"
    print("Request completed ", " result: ", result, " response_code: ", response_code, " body: ", body)

func set_texture(photo_name):
    var image =
    image.load("user://%s.png" %photo_name)
    var image_texture =
    $TextureRect.texture = image_texture

func _on_Button1_pressed():

func _on_Button2_pressed():

func _on_Button3_pressed():

func _on_Button4_pressed():

I have no idea what is happening. The body size is just 2141681. It is way beyond the limit of integer but it gives me -1.

I also have this problem in version 3.3
In version 3.2.3 it works correctly

dpensky | 2021-05-13 18:25