Universal-Arduino-Telegram-Bot icon indicating copy to clipboard operation
Universal-Arduino-Telegram-Bot copied to clipboard

Any chance of send image from spiffs?

Open danbicks opened this issue 7 years ago • 2 comments

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

Is this possible?

Cheers

Dans

danbicks avatar Jun 23 '18 18:06 danbicks

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();
}

svenp avatar Jun 22 '19 11:06 svenp

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, [email protected] 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 .

witnessmenow avatar Jun 22 '19 11:06 witnessmenow