Can't send image to telegram. Need help!

Godot Version

4.2

Question

Hello, I’m trying to send an image(or log.txt) from the game to telegram via bot api, but nothing works. Has anyone tried to do something like this? Maybe there is a working variant. Messages are sent perfectly, but the image does not work.

Can you show your code? And also give us a link to the API, so that we can see what format it is expecting

Telegram Bot API and my code:

func send_document(file_path: String) -> void:
	var telegram_document: TelegramDocument = TelegramDocument.new(bot_config.admin_chat_id, "This is a test document", file_path, TelegramDocument.ParseMode.MARKDOWN)
	var headers: PackedStringArray = [
		"Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"
	]
	var url: String = "https://api.telegram.org/bot" + bot_config.token + "/sendDocument"
	http_request.request(url, headers, HTTPClient.METHOD_POST, telegram_document.to_form_data())

class TelegramDocument:
	enum ParseMode {
		NONE,
		MARKDOWN,
		HTML
	}

	var chat_id : String
	var caption : String
	var parse_mode : String
	var disable_notification : bool
	var document_path: String

	var _parse_modes: Dictionary = {
		ParseMode.NONE: "",
		ParseMode.MARKDOWN: "Markdown",
		ParseMode.HTML: "HTML"
	}

	func _init(message_chat_id: String, message_caption: String, message_document_path: String, message_parse_mode: ParseMode = ParseMode.NONE, message_disable_notification: bool = false) -> void:
		chat_id = message_chat_id
		caption = message_caption
		parse_mode = _parse_modes.get(message_parse_mode, ParseMode.NONE)
		disable_notification = message_disable_notification
		document_path = message_document_path

	
	func to_form_data() -> String:
		var boundary: String = "----WebKitFormBoundary7MA4YWxkTrZu0gW"
		var form_data: String = ""
		form_data += "--%s\n" % boundary
		form_data += 'Content-Disposition: form-data; name="chat_id"\n\n'
		form_data += chat_id + "\n"
		form_data += "--%s\n" % boundary
		form_data += 'Content-Disposition: form-data; name="document"; filename="%s"\n' % document_path.get_file()
		form_data += 'Content-Type: image/jpg\n\n'
		form_data += Marshalls.raw_to_base64(FileAccess.get_file_as_bytes(document_path)) + "\n"
		form_data += "--%s--" % boundary
		return form_data

Output:

0	400	["Server: nginx/1.18.0", "Date: Tue, 27 Feb 2024 00:24:05 GMT", "Content-Length: 0", "Connection: keep-alive", "Strict-Transport-Security: max-age=31536000; includeSubDomains; preload", "Access-Control-Allow-Origin: *", "Access-Control-Expose-Headers: Content-Length,Content-Type,Date,Server,Connection"]