Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | blarfyshow |
I’m trying to upload a base64 encoded image to imgbb, but it gives this error:
{"status_code":400,"error":{"message":"Empty upload source.","code":130},"status_txt":"Bad Request"}
How do I fix this?
extends Node2D
var key = "INSERTKEY"
func _ready():
var file = File.new()
file.open("res://icon.png", File.READ)
var base_64_data = Marshalls.raw_to_base64(file.get_buffer(file.get_len()))
var data = {
"image":str(base_64_data)
}
_make_post_request(str("https://api.imgbb.com/1/upload?expiration=600&key=",key),data, false)
func _make_post_request(url, data_to_send, use_ssl):
var query = JSON.print(data_to_send)
var headers=["Content-Type: multipart/form-data;"]
$HTTPRequest.request(url, headers, use_ssl, HTTPClient.METHOD_POST, query)
func _on_HTTPRequest_request_completed(_result, _response_code, _headers, body):
print(body.get_string_from_utf8())