Helper class for accessing the file system and serving file content. More...
#include <HttpFileserver.h>
Collaboration diagram for FileHandler:Public Member Functions | |
| FileHandler () | |
| Construct a new FileHandler object. | |
| bool | init () |
| Initialize and mount the storage (e.g., SD card). | |
| bool | listDirectory (const std::string &path, std::vector< FileInfo > &out) |
| Return a list of a given directory. | |
| bool | serveFile (HttpResponse &res, const char *uri) |
| Serve a file to the client via the HttpResponse object. | |
Public Attributes | |
| bool | mounted = false |
| Flag indicating whether storage is mounted. | |
Private Attributes | |
| StorageManager * | storageManager |
Definition at line 27 of file HttpFileserver.h.
| FileHandler::FileHandler | ( | ) |
| bool FileHandler::init | ( | ) |
Initialize and mount the storage (e.g., SD card).
Definition at line 53 of file HttpFileserver.cpp.
References AppContext::getTypeKey(), StorageManager::mount(), and TRACE.
Here is the call graph for this function:| bool FileHandler::listDirectory | ( | const std::string & | path, |
| std::vector< FileInfo > & | out | ||
| ) |
Return a list of a given directory.
| path | Directory path to list. |
| path | Directory path to list. |
Definition at line 69 of file HttpFileserver.cpp.
References AppContext::getTypeKey().
Referenced by HttpFileserver::handle_list_directory().
Here is the call graph for this function:
Here is the caller graph for this function:| bool FileHandler::serveFile | ( | HttpResponse & | res, |
| const char * | uri | ||
| ) |
Serve a file to the client via the HttpResponse object.
| res | HTTP response object. |
| uri | URI or path to the file. |
| res | HTTP response object. |
| uri | URI or path to the file. |
Definition at line 76 of file HttpFileserver.cpp.
References StorageManager::exists(), HttpResponse::finish(), StorageManager::getFileSize(), getMimeType(), AppContext::getTypeKey(), StorageManager::isMounted(), StorageManager::mount(), StorageManager::readFileString(), JsonResponse::sendError(), HttpResponse::set(), HttpResponse::start(), storageManager, STREAM_SEND_DELAY_MS, StorageManager::streamFile(), TRACE, and HttpResponse::writeChunk().
Referenced by HttpFileserver::handle_static_request(), and HttpResponse::sendFile().
Here is the call graph for this function:
Here is the caller graph for this function:| bool FileHandler::mounted = false |
Definition at line 58 of file HttpFileserver.h.
|
private |
Definition at line 61 of file HttpFileserver.h.
Referenced by serveFile().