From f3f378a54aa463adb960b109f63ce306cd9623df Mon Sep 17 00:00:00 2001 From: Martin Bauer Date: Sun, 21 Jun 2020 13:23:52 +0200 Subject: [PATCH] WebDAV get file --- firmware/lib/esphttp/WebDAV.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/firmware/lib/esphttp/WebDAV.cpp b/firmware/lib/esphttp/WebDAV.cpp index cfeac21..b801516 100644 --- a/firmware/lib/esphttp/WebDAV.cpp +++ b/firmware/lib/esphttp/WebDAV.cpp @@ -117,13 +117,29 @@ std::function webdavHandler(const char *uriPrefix, switch (req->method) { case HTTP_GET: + { + auto filename = uriToFileName(uri, spiffsFolder); + Serial.printf("GET filename %s\n", filename.c_str()); + auto file = portablefs::open(filename.c_str(), "r"); + if (file.available()) + { + uint8_t *buffer = (uint8_t *)heap_caps_malloc(file.size(), MALLOC_CAP_SPIRAM); + file.read(buffer, file.size()); + httpd_resp_set_hdr(req, "Content-Type", "application/x-msgpack"); + httpd_resp_send(req, (char *)buffer, file.size()); + free(buffer); + } + else + httpd_resp_send_404(req); + break; + } case HTTP_PROPFIND: { size_t bytesWritten = webdavFileListingSpiffs(webdavBuffer, WEBDAV_BUFF_LEN, spiffsFolder); httpd_resp_send(req, webdavBuffer, bytesWritten); break; } - case HTTP_DELETE: + case HTTP_DELETE: { httpd_resp_set_hdr(req, "Content-Type", "text/plain");