witnessmenow / Universal-Arduino-Telegram-Bot

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

Any chance of send image from spiffs? #83

Open danbicks opened 6 years ago

danbicks commented 6 years ago

Hi would be brilliant to have an example that allows you to send an image stored in spiffs..

Is this possible?

Cheers

Dans

svenp commented 5 years ago

Hi Dans, i had same Idea and here is the code for you....

readFile(SPIFFS, "/img.jpg");

void readFile(fs::FS &fs, const char * path){
    Serial.printf("Reading file: %s\r\n", path);

   file = fs.open(path);
    if(!file || file.isDirectory()){
        Serial.println("- failed to open file for reading");
        return;
    }

     sent = bot.sendPhotoByBinary(chat_id, "image/jpeg", file.size(),
            isMoreDataAvailable,
            getNextByte);
        if (sent) {
          Serial.println("was successfully sent");
        } else {
          Serial.println("was not sent");
        }

file.close();
}
witnessmenow commented 5 years ago

If you are sending a static image that is not generated by the Arduino itself, you might consider hosting it somewhere like Imgur and then use sendPhotoByUrl

https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot/blob/master/examples/ESP8266/SendPhoto/PhotoFromURL/PhotoFromURL.ino

On Sat, 22 Jun 2019, 12:35 svenp, notifications@github.com wrote:

Hi Dans, i had same Idea and here is the code for you....

readFile(SPIFFS, "/img.jpg");

void readFile(fs::FS &fs, const char * path){ Serial.printf("Reading file: %s\r\n", path);

file = fs.open(path); if(!file || file.isDirectory()){ Serial.println("- failed to open file for reading"); return; }

 sent = bot.sendPhotoByBinary(chat_id, "image/jpeg", file.size(),
        isMoreDataAvailable,
        getNextByte);
    if (sent) {
      Serial.println("was successfully sent");
    } else {
      Serial.println("was not sent");
    }

file.close(); }

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot/issues/83?email_source=notifications&email_token=AAL5PQSDTZFFUF2Z7TSK3ETP3YE7FA5CNFSM4FGTRZMKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYKHPYY#issuecomment-504657891, or mute the thread https://github.com/notifications/unsubscribe-auth/AAL5PQUQR4ZBQP4ZLYM5KITP3YE7FANCNFSM4FGTRZMA .