-->
Page 1 of 1

Sending an image file from a webserver

PostPosted: Mon Jun 12, 2017 12:42 am
by kentbkiwi
Is it possible to send an embedded image from an ESP8266 set up as a webserver (using a WeMos D1 mini)? If so, are there any limits. I would like to have a background image which is stored in flash.

Re: Sending an image file from a webserver

PostPosted: Tue Jun 13, 2017 1:43 pm
by gbafamily1
Assuming you are interested in ESP8266 Arduino, take a look at the FSBrowser example for serving web pages from Flash (SPIFFS).

https://github.com/esp8266/Arduino/tree ... /FSBrowser

Re: Sending an image file from a webserver

PostPosted: Wed Jun 14, 2017 6:05 am
by GengusKahn
Hi there, just use "server.streamfFle".....

Pass the path to the file and descriptor to server.streamFile, in the sketch / html just use message += "<body background=\"/eye.gif\">";

Code: Select all
//Use this to send an Image or File from SPIFFS
void loadImg(String path, String TyPe)
{ // path=Filename(including root "/"), TyPe= html descriptor
 if(SPIFFS.exists(path)){
    File file = SPIFFS.open(path, "r");
    server.streamFile(file, TyPe);
    file.close();
  }
}
in setup
//  Any Images need to be uploaded to SPIFFS...!!!
  server.on("/eye.gif", []() { loadImg("/flame.gif", "image/gif"); } );  // or jpg

Re: Sending an image file from a webserver

PostPosted: Thu Jan 18, 2018 10:07 pm
by flagtrax
Hi @GengusKahn, after looking at some of the information on the stream class here
https://www.arduino.cc/reference/en/language/functions/communication/stream/
I simply got confused. My experience is limited, I was wondering if you could elaborate on your example a bit. Or perhaps point me to some examples. I am very much interested in understanding this particular action using the 8266. Can this process be incorporated into say an HTML button object or other uses? That is one of my goals. Thanks and much obliged for any steering..