Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Gary_CHAN |
Hello,
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:
“>2MB”
1Ur1r39Qgp0yWF0vZb56yCMH8eaewfxRi
1uIRR82q_loE1QRSJGJ8xIQffRgLRM_1W
1vuU6yWs-W2GJAMPrkiFatTT9M_kL5ixm
“<2MB”
1_XGLScHjEq0Imbby1G0_GGUaF0Qnw5Qa
1QzzrkV7W9q7jRtk4p7g92f4auT0MeEUK
1-aOXkKJPqjtiTs0R7cxG-zWKw0SNuvmg
Just replace the string after “id=” in $HTTPRequest.request(“https://drive.google.com/uc?id=1Wvx0Rqk3cPIgKrDQAdjHtqdN4UxTlqzq”)
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():
set_process(false)
func _process(delta):
status = $HTTPRequest.get_http_client_status()
downloaded_bytes = $HTTPRequest.get_downloaded_bytes()
body_size = $HTTPRequest.get_body_size()
print("---------------------------------")
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"
else:
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)
set_process(false)
func set_texture(photo_name):
var image = Image.new()
image.load("user://%s.png" %photo_name)
var image_texture = ImageTexture.new()
image_texture.create_from_image(image)
$TextureRect.texture = image_texture
func _on_Button1_pressed():
$HTTPRequest.set_download_file("user://Below_2_MB.png")
$HTTPRequest.request("https://drive.google.com/uc?id=1Wvx0Rqk3cPIgKrDQAdjHtqdN4UxTlqzq")
set_process(true)
func _on_Button2_pressed():
$HTTPRequest.set_download_file("user://Exceed_2_MB.png")
$HTTPRequest.request("https://drive.google.com/uc?id=1hVDbZT6dZdcmppgE_pfsDNslddvLs6Rq")
set_process(true)
func _on_Button3_pressed():
set_texture("Below_2_MB")
func _on_Button4_pressed():
set_texture("Exceed_2_MB")
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