Load_jpg_from_buffer giving error 31 but downloaded image is ok

Godot Version

Godot v4.2.1

Question

I am dowloading and palcing in runtime images from an API.
As far as I know the way of doing it is like so:

func _on_http_request_request_completed(result, response_code, headers, body):
	if response_code == 200:
		var img = Image.new()
		var img_error = img.load_jpg_from_buffer(body)
		if img_error != OK:
			print("error loading data to img:")
			print(img_error)

		var texture = ImageTexture.new()
		texture.create_from_image(img)
		
		$Sprite2D.texture = texture
		$MarginContainer/TextureRect.texture = texture
	else:
		print("not ok")

But Im getting an errorcode 31.
The funny part is that Im also downloading the image as a file, and thats working fine.
I dont know what im possibly doing wrong, Ive checked here for other solutions but nothing seems to be working for me.
Tried other links ,other formats, changing from https to http…

here is the pastebin of all the file: extends Node2D@export var url = ""var extfunc _ready(): ext = url.ge - Pastebin.com
but there is not a lot more to see really

I’ve solved, The problem was that previously I changed the httpRequest to download the image, this was causing that the body response became malformed for the load jpg from buffer method.
Just removed $HTTPRequest.set_download_file("test_file.jpg") from the code and it worked
This is the intended behaviour? Looks fishy

Thats interesting, I looked thru the source code and I don’t see why it would do that unless I’m overlooking something.

Definitely something that might have to be looked at further. Fortunately its not that bad.

Is worth a Git issue describing more in depth the behaviour?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.