Hi

I have made a database with castle db and want to load the images from there into my game. I get the base64 string from the image i need and want to transform it to a PoolByteArray with the base64_to_raw() method. Here i get the following error:

ERROR: base64_to_raw: Condition "CryptoCore::b64_decode(&w[0], buf.size(), &arr_len, (unsigned char *)cstr.get_data(), strlen) != OK" is true. Returned: PoolVector<uint8_t>()

Code:

func set_icon(data):
	
	icon = data["icon"]
	
	var data_read2 = File.new()
	data_read2.open("res://Items/new.img", File.READ)
	var data2 = parse_json(data_read2.get_as_text())
	data_read2.close()
		
	
	var split = data2[icon].split(",", true, 1)
	var base64_string = split[1]
	var byte_pool = Marshalls.base64_to_raw(base64_string)
	
	
	#print(base64_string)
		
	var i = Image.new()
	
	i.load_png_from_buffer(byte_pool)
	var t = ImageTexture.new()
	t.create_from_image(i)
	sprite.texture = t

I hope somebody can solve my problem.

Welcome to the forums @ginro!

Based on the error, I'd say the issue is related to base64_string, as it seems there is some char related issues there. I would suggest printing base64_string and seeing if you can deduce what is going on there.

Also, are you sure you need to convert the image from base64? The error seems to indicate it is related to encryption (CryptoCore), which may be contributing to the issue? If you are storing the image using Godot's built-in file stuff, you can use store_var to store an image and get_var to retrieve said image. I've used it before for this kind of stuff and it works decently.

@TwistedTwigleg thanks for your reply.

I already printed the base64_string and testet it on [https://www.base64decode.net/base64-image-decoder](http:// "https://www.base64decode.net/base64-image-decoder"). There it worked fine and i got the image as the result. I can work around converting the image from base64 by storing the image directly in godot but that would involve some string manipulation or numeration of the images. Adding more items like that would be a bit more work, when adding a new item in castle db. At this point solving the problem is pure curiosity (because the function of storing images exist in castle db).

a year later

Sorry for the zombie lol. I was having the same problem and figured it out. Some images don't work unless there is a '+' character at the end of the string. And the img file isn't formatted properly: I used find/replace to fix both parts:
replace data:image/png;base64, with " replace ", with +", and manually add + to the last value in the dictionary.

a year later