如何在TIdHttp中发布带有汉字的文件

时间:2019-06-27 06:00:23

标签: delphi idhttp

我正在使用电报bot API发送文档。一切正常,直到我需要发送带有中文字符的文件。文件已正确发送,但文件名是垃圾。这是我的测试代码:

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;

如何正确发布带有中文文件名的文件?我哪里出错了?

*****编辑***** 文件名是中文,例如:强大.txt。我仍然收到完整的文件,但文件名现在是: = UTF-8 B 5paw5LiW55WMXzIwMTktMDYtMjUuVFhU = ,这是不正确的。

0 个答案:

没有答案
相关问题