Re: Text files download blank, with no text --solved.
Posted: Tue Jan 29, 2019 2:19 pm
Thank you schufti; I completely missed that difference.
Working great. Appreciate the help!
William
Working great. Appreciate the help!
William
-->
Open Community Forum for ESP8266, Come share Arduino and IoT (Internet of Things)
https://www.esp8266.com/
void listen() // Listen for client connection
{
// Check if a client has connected
[b]client = server.available();[/b]
if (client)
{
// Process this request until it completes or times out.
// Note that this is explicitly limited to handling one request at a time!
void readFile()
{
digitalWrite(online, HIGH); //turn-on online LED indicator
String filename = (const char *)&MyBuffer;
Serial.print("File: ");
Serial.println(filename);
File webFile = SPIFFS.open(filename, "r");
if (!webFile)
{
Serial.println("File failed to open");
Serial.println("\n");
}
else
{
char buf[1024];
int siz = webFile.size();
//.setContentLength(str.length() + siz);
//webserver.send(200, "text/plain", str);
while (siz > 0)
{
size_t len = std::min((int)(sizeof(buf) - 1), siz);
webFile.read((uint8_t *)buf, len);
client.write((const char*)buf, len);
//client.write(webFile);
siz -= len;
}
webFile.close();
}
error = 0;
delayTime = 1000;
MyBuffer[0] = '\0';
// digitalWrite(online, LOW); //turn-off online LED indicator
listen();
}