Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Subhajit Das
#48655 How to access files in SPIFFS as const char*?
Actually I want to use sendContent_P(const char*) to send data or something like that, which dosen't involve too much RAM, rather done using flash.
Can anyone help me?
Last edited by Subhajit Das on Sun Jun 26, 2016 1:05 am, edited 1 time in total.
User avatar
By anotherjoe
#48660 Where you said you wanted to use sendContent_P, I assume you mean ESP8266WebServer::sendContent_P?
If that's right then something like this would be syntactically correct:

Code: Select allFile file = SPIFFS.open(path, "r");      
String fileStr = file.readString();
webserver->sendContent_P(fileStr.c_str());      
file.close();


But if you wanted this to use as little RAM as possible, then I expect that filling a string like that just to be able to use ESP8266WebServer::sendContent_P probably isn't going to be the best way to go.

Given that in most circumstances you always have to do the file open part (unless you're getting really low level with SPIFFS) then perhaps the easiest most lightweight way to go is to just send the file directly via ESP8266WebServer::streamFile e.g. :

Code: Select allString contentType; //setup the response content type using logic based on the file being sent prior to calling streamFile
File file = SPIFFS.open(path, "r");
webserver->streamFile(file, contentType);
file.close();