-->
Page 1 of 1

(No, but Solved) Access files in SPIFFS as const char*?

PostPosted: Mon Jun 06, 2016 12:42 am
by Subhajit Das
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?

Re: Access files in SPIFFS as const char*?

PostPosted: Mon Jun 06, 2016 1:38 am
by anotherjoe
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();

Re: Access files in SPIFFS as const char*?

PostPosted: Tue Jun 21, 2016 12:59 am
by martinayotte
send_P() and sendContent_P() are strictly to be use with PROGMEM, not from streams coming from SPIFFS.

Re: Access files in SPIFFS as const char*?

PostPosted: Sun Jun 26, 2016 1:04 am
by Subhajit Das
martinayotte wrote:send_P() and sendContent_P() are strictly to be use with PROGMEM, not from streams coming from SPIFFS.

Thanks.