Skip to content

Send documents: bug resolved in sendMultipartFormDataToTelegram function (ESP32) #233

@sfekilou

Description

@sfekilou

I wanted to use the function sendMultipartFormDataToTelegram to send a text file. So I made this call to the function:
String response=bot->sendMultipartFormDataToTelegram("sendDocument","document","mesures.txt",X,Chat_id,size,isMoreDataAvailable,getNextByte,nullptr,nullptr);
I didn't know what to put in the X chain. I tried with "image/png" instead of X:
String response = bot-> sendMultipartFormDataToTelegram ("sendDocument","document","mesures.txt","image/png",chat_id,size,isMoreDataAvailable,getNextByte,nullptr,nullptr);
Then, on executing, the function blocked. While debugging, I noticed that the function sendMultipartFormDataToTelegram of UniversalTelegramBot.cpp was blocking at the level of the call to client->println(F("")); I replaced this line by: client->print(F("\r\n")); (note: "print" instead of "println" !).
It works now, I received my file. And it also works with "" instead of "image/png".

Note: you must add these functions in your main code:

File myFile; //on global memory

bool isMoreDataAvailable()
{
  return(myFile.available());
}

byte getNextByte()
{
  return((byte)myFile.read());
}

and open file before calling sendMultipartFormDataToTelegram function:

int size;
myFile=FFat.open("/mesures.txt","r"); //in my case the file is on the FFAT
size=myFile.size();
String response=bot->sendMultipartFormDataToTelegram("sendDocument", "document","mesures.txt","",chat_id,size,isMoreDataAvailable,getNextByte, nullptr, nullptr);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions