server.streamFile not working properly
Posted: Fri Oct 28, 2016 4:34 pm
Hi, my first post so please bear with me . . .
I am working on a Web cam using the Adafruit HUZZAH ESP8266. I am using the TTL Serial JPEG Camera to take an image. The web page initially sends a response with an <img> tag that then triggers the handle_picture function. This should simply send a jpeg file to the browser.
The problem I am having appears to be with the server.streamFile function. In the snippet of code below it appears that the function does not read and send the entire file.
As you can see, the output shows a file of 45012 bytes however, the streamFile only sends 4380 bytes!
I have looked thru many of the related posts however, I could not find a solution to similar posts / problems. I would appreciate any solutions / advice!
I am working on a Web cam using the Adafruit HUZZAH ESP8266. I am using the TTL Serial JPEG Camera to take an image. The web page initially sends a response with an <img> tag that then triggers the handle_picture function. This should simply send a jpeg file to the browser.
The problem I am having appears to be with the server.streamFile function. In the snippet of code below it appears that the function does not read and send the entire file.
Code: Select all
void handle_picture() {
byte clientBuf[64];
char filename[13];
strcpy(filename, "IMAGE01.JPG");
filename[5] = '0' + FileNum / 10;
filename[6] = '0' + FileNum % 10;
int32_t time = millis();
// strcpy(filename, "/test1.jpg"); // DEBUG only
f = SPIFFS.open(filename, "r");
if (!f) {
Serial.print("file open failed: ");
Serial.println(filename);
} else {
Serial.print("file opened: ");
Serial.println(filename);
}
int filesize = f.size();
Serial.print("File size ");
Serial.println(filesize); //For debugging only
String WebString = "";
WebString += "HTTP/1.1 200 OK\r\n";
WebString += "Content-Type: image/jpeg\r\n";
WebString += "Content-Length: " + String(filesize) + "\r\n";
WebString += "\r\n";
server.sendContent(WebString);
Serial.println (WebString);
ESP.wdtFeed();
count = 0;
size_t sent = server.streamFile(f,"image/jpeg");
Serial.print(sent);
Serial.println(" Bytes sent!");
f.close();
time = millis() - time;
Serial.print(time); Serial.println(" ms elapsed");
}// END handle_picture
As you can see, the output shows a file of 45012 bytes however, the streamFile only sends 4380 bytes!
Code: Select all
Image size: 640x480
HTTP server started
Picture taken!
File number = 6
Filename: IMAGE06.JPG
Storing 45012 byte image.
...........................................*
File stored!
24623 ms elapsed
170853 mS Elasped for snapshot.
file opened: IMAGE06.JPG
File size 45012
HTTP/1.1 200 OK
Content-Type: image/jpeg
Content-Length: 45012
4380 Bytes sent!
43 ms elapsed
I have looked thru many of the related posts however, I could not find a solution to similar posts / problems. I would appreciate any solutions / advice!