File Server Example : Check longer than allowed filenames when converting from URIs to filepaths

This change prevents buffer overflows in case of really long file paths.

Other changes:
* Remove query (?) and fragment (#) component from URI when converting to file path
* /index.html and favicon.ico can be overridden by files with same name and path in SPIFFS
* README.md updated
This commit is contained in:
Anurag Kar
2019-04-26 01:28:33 +05:30
parent df9113e0e1
commit 59afbe4eed
2 changed files with 126 additions and 100 deletions
@@ -2,13 +2,23 @@
(See the README.md file in the upper level 'examples' directory for more information about examples.)
HTTP file server example demonstrates file serving using the `esp_http_server` component of ESP-IDF:
1. URI `/path/filename` for GET command downloads the corresponding file (if exists)
2. URI `/upload` POST command for uploading the file onto the device
3. URI `/delete` POST command for deleting the file from the device
HTTP file server example demonstrates file serving with both upload and download capability, using the `esp_http_server` component of ESP-IDF. The following URIs are provided by the server:
| URI | Method | Description |
|----------------------|---------|-------------------------------------------------------------------------------------------|
|`index.html` | GET | Redirects to `/` |
|`favicon.ico` | GET | Browsers use this path to retrieve page icon which is embedded in flash |
|`/` | GET | Responds with webpage displaying list of files on SPIFFS and form for uploading new files |
|`/<file path>` | GET | For downloading files stored on SPIFFS |
|`/upload/<file path>` | POST | For uploading files on to SPIFFS. Files are sent as body of HTTP post requests |
|`/delete/<file path>` | POST | Command for deleting a file from SPIFFS |
File server implementation can be found under `main/file_server.c` which uses SPIFFS for file storage. `main/upload_script.html` has some HTML, JavaScript and Ajax content used for file uploading, which is embedded in the flash image and used as it is when generating the home page of the file server.
## Note
`/index.html` and `/favicon.ico` can be overridden by uploading files with same pathname to SPIFFS.
## Usage
* Configure the project using `make menuconfig` and goto `Example Configuration` ->