I'm using telegram bot api to send a document. it was working OK until I need to send files with chinese characters. the file is sent correctly but the filename is garbage. Here is my code with tests :
procedure TSendThread.SendTelegramMessage(filename, chat_id, aCaption: string);
const
c_url = 'https://api.telegram.org/bot893812066:YOUR_TOKEN/sendDocument';
var
idHttpEx : TIdHTTPEx; // this is good as TIdHttp
aParam : TIdMultipartFormDataStream;
begin
idHttpEx := TIdHTTPEx.Create(nil);
aParam := TIdMultipartFormDataStream.Create;
try
aParam.AddFormField('chat_id', chat_id);
aParam.AddFormField('caption', aCaption, 'utf-8').ContentTransfer := '8bit';
aParam.AddFile('document', filename); //original code
// test 1
// with aParam.AddFile('document', filename) do
// begin
// Charset := 'utf-8';
// ContentTransfer := '8bit';
// end;
// test 2
// aParam.AddFile('document', filename).Charset := 'utf-8';
// test 3
// aParam.AddFile('document', filename, 'utf-8').ContentTransfer := '8bit';
// test 4
// aParam.AddFile('document', UTF8Encode(filename)).ContentTransfer := '8bit';
idHttpEx.Post(c_url, aParam);
finally
aParam.Free;
idHttpEx.Free;
end;
end;
How do I post files with chinese filename correctly? Where did I go wrong?
*****EDIT***** The filename is chinese like : 强大.txt. I still receive the file intact but the filename is now : = UTF-8 B 5paw5LiW55WMXzIwMTktMDYtMjUuVFhU = which is incorrect.