Sebastian Schocke / ESP8266_WebServer

Files at this revision

API Documentation at this revision

Comitter:
sschocke
Date:
Thu Jan 01 10:22:31 2015 +0000
Parent:
0:56c72c87d2f5
Child:
2:6079554681d6
Commit message:
Added facility to send files

Changed in this revision

ESP8266_WebServer.cpp Show annotated file Show diff for this revision Revisions of this file
ESP8266_WebServer.h Show annotated file Show diff for this revision Revisions of this file
--- a/ESP8266_WebServer.cpp	Thu Jan 01 10:11:55 2015 +0000
+++ b/ESP8266_WebServer.cpp	Thu Jan 01 10:22:31 2015 +0000
@@ -209,6 +209,16 @@
     sendResponse(linkID, replySize);
 }
 
+void ESP8266_WebServer::SendFile(int linkID, FileHandle* file, const char* mimeType) {
+    sprintf(response, "HTTP/1.1 200 OK\r\nContent-Type:%s\r\nContent-Length: %d\r\n\r\n", mimeType, file->flen());
+    sendResponse(linkID, strlen(response));
+    int numBytes = file->read(response, sizeof(response));
+    while( numBytes > 0) {
+        sendResponse(linkID, numBytes);
+        numBytes = file->read(response, sizeof(response));
+    }
+}
+
 ESP8266_WebRequest::ESP8266_WebRequest(const char* packet, Serial* debug) {
     int sz = strlen(packet);
     data = (char *)malloc(sz+1);
--- a/ESP8266_WebServer.h	Thu Jan 01 10:11:55 2015 +0000
+++ b/ESP8266_WebServer.h	Thu Jan 01 10:22:31 2015 +0000
@@ -65,6 +65,7 @@
         void Send404Error(int linkID);
         void SendReply(int linkID, std::string reply, const char* mimeType);
         void SendReply(int linkID, const char* reply, int replySize, const char* mimeType);
+        void SendFile(int linkID, FileHandle* file, const char* mimeType);
 };
 
 #endif
\ No newline at end of file