witnessmenow / Universal-Arduino-Telegram-Bot

Use Telegram on your Arduino (ESP8266 or Wifi-101 boards)
MIT License
1.12k stars 307 forks source link

Send image from file often failed. Try to change img name random. Works better. #123

Open svenp opened 5 years ago

svenp commented 5 years ago

Hi,

after sending 2 or 3 images there is no more img sending. Maby the telegram api will not accept a lot of images with same name. So i changed the Function sendPhotoByBinary to generate a random image name witch is sending to telegram api. Looks like more stable


String UniversalTelegramBot::sendPhotoByBinary(
    String chat_id, String contentType, int fileSize,
    MoreDataAvailable moreDataAvailableCallback,
    GetNextByte getNextByteCallback) {

  if (_debug)
    Serial.println("SEND Photo");
        String name = "img";
    name += random(99);
        name += ".jpg";
    int n = name.length();
    char name_array[n + 1];
    strcpy(name_array, name.c_str()); 

    String response = sendMultipartFormDataToTelegram(
      "sendPhoto", "photo", name_array, contentType, chat_id, fileSize,
       moreDataAvailableCallback, getNextByteCallback);
//  String response = sendMultipartFormDataToTelegram(
//      "sendPhoto", "photo", "img.jpg", contentType, chat_id, fileSize,
//      moreDataAvailableCallback, getNextByteCallback);

  if (_debug)
    Serial.println(response);

  return response;
}

Regards Sven