编码文件名 Telegram 机器人上传文件

Evg*_*Evg 5 .net c# character-encoding telegram-bot

我尝试使用 telegram bot api 上传文件。文件已发送,但如果文件名包含俄语字母,则接收者会看到编码的文件名。我发现文件名是用 Base64 和 Utf-8 编码的

\n\n
string url = "https://api.telegram.org/bot" + _keyBotTelegram + "/sendDocument";\n\nstring ttt = @"K:\\\xd0\x9d\xd0\xbe\xd0\xb2\xd1\x8b\xd0\xb9 \xd1\x82\xd0\xb5\xd0\xba\xd1\x81\xd1\x82\xd0\xbe\xd0\xb2\xd1\x8b\xd0\xb9 \xd0\xb4\xd0\xbe\xd0\xba\xd1\x83\xd0\xbc\xd0\xb5\xd0\xbd\xd1\x82.txt";\nstring fileName = ttt.Split(\'\\\\\').Last();\nvar bot = new Telegram.Bot.Api("129368276:AAEW-Q7Jv8qWaFvwYk2iD4mXZyt9Q");\nusing (var stream = System.IO.File.Open(pathToDocument, FileMode.Open))\n{\n    FileToSend fts = new FileToSend();\n    fts.Content = stream;\n    fts.Filename = pathToDocument.Split(\'\\\\\').Last();\n    var test = await bot.SendDocumentAsync(ChatID, fts, caption);\n    // "Report",).SendPhoto("@channel Name or chat_id", fts, "My Text");\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

文件名

\n\n

如何将unicode编码的文件发送到客户端以保存文件全名(包括文件扩展名)

\n\n

尝试将文件名编码为 Utf8

\n\n
// Create two different encodings.\nEncoding utf8 = Encoding.UTF8;\nEncoding unicode = Encoding.Unicode;\n\n// Convert the string into a byte array.\nbyte[] unicodeBytes = unicode.GetBytes(fileName);\n\n// Perform the conversion from one encoding to the other.\nbyte[] utf8Bytes = Encoding.Convert(unicode, utf8, unicodeBytes);\n\n// Convert the new byte[] into a char[] and then into a string.\nchar[] utf8Chars = new char[utf8.GetCharCount(utf8Bytes, 0, utf8Bytes.Length)];\nutf8.GetChars(utf8Bytes, 0, utf8Bytes.Length, utf8Chars, 0);\nstring utf8String = new string(utf8Chars);\n\nfileName = utf8String;\n
Run Code Online (Sandbox Code Playgroud)\n\n

结果文件名

\n