|
9 | 9 | any redistribution
|
10 | 10 | *********************************************************************/
|
11 | 11 |
|
12 |
| -/* This example demo how to expose on-board external Flash as USB Mass Storage. |
13 |
| - * Following library is required |
| 12 | +/* This example is based on "arduino-esp32/libraries/WebServer/examples/FSBrowser" |
| 13 | + * to expose on-board external Flash as USB Mass Storage and webserver. Both interfaces |
| 14 | + * can make changes to file system |
| 15 | + * |
| 16 | + * How to run this example |
| 17 | + * 1. Create secrets.h and define your "SECRET_SSID" and "SECRET_PASSWORD" |
| 18 | + * 2. Compile and upload this sketch |
| 19 | + * 3. Your ESP will be expose as MassStorage device. |
| 20 | + * 4. If it is your first run (otherwise skip this step): |
| 21 | + * - you may need to format the drive as FAT. Note: If your PC failed to format, you could format |
| 22 | + * it using follow sketch "https://github.com/adafruit/Adafruit_SPIFlash/tree/master/examples/SdFat_format" |
| 23 | + * - Copy all files in 'data/' folder of this example to the root directory of the MassStorage disk drive |
| 24 | + * 5. When prompted, open http://esp32fs.local/edit to access the file browser |
| 25 | + * 6. Try to modify USB drive then refresh your browser to see if the change is updated |
| 26 | + * 7. |
| 27 | + * |
| 28 | + * NOTE: Following library is required |
14 | 29 | * - Adafruit_SPIFlash https://github.com/adafruit/Adafruit_SPIFlash
|
15 | 30 | * - SdFat https://github.com/adafruit/SdFat
|
16 |
| - * |
17 |
| - * Note: Adafruit fork of SdFat enabled ENABLE_EXTENDED_TRANSFER_CLASS and FAT12_SUPPORT |
18 |
| - * in SdFatConfig.h, which is needed to run SdFat on external flash. You can use original |
19 |
| - * SdFat library and manually change those macros |
20 | 31 | */
|
21 | 32 |
|
22 | 33 | #include "SPI.h"
|
@@ -118,7 +129,7 @@ void setupServer(void)
|
118 | 129 | MDNS.begin(host);
|
119 | 130 | DBG_SERIAL.print("Open http://");
|
120 | 131 | DBG_SERIAL.print(host);
|
121 |
| - DBG_SERIAL.println(".local/edit to see the file browser"); |
| 132 | + DBG_SERIAL.println(".local/edit to access the file browser"); |
122 | 133 |
|
123 | 134 | //SERVER INIT
|
124 | 135 |
|
@@ -272,12 +283,15 @@ void handleFileUpload() {
|
272 | 283 | filename = "/" + filename;
|
273 | 284 | }
|
274 | 285 | DBG_SERIAL.print("handleFileUpload Name: "); DBG_SERIAL.println(filename);
|
275 |
| - fsUploadFile = fatfs.open(filename, O_WRITE); |
| 286 | + fsUploadFile = fatfs.open(filename, O_WRITE | O_CREAT | O_TRUNC); |
276 | 287 | filename = String();
|
277 | 288 | } else if (upload.status == UPLOAD_FILE_WRITE) {
|
278 |
| - //DBG_SERIAL.print("handleFileUpload Data: "); DBG_SERIAL.println(upload.currentSize); |
| 289 | + DBG_SERIAL.print("handleFileUpload Data: "); DBG_SERIAL.println(upload.currentSize); |
279 | 290 | if (fsUploadFile) {
|
280 | 291 | fsUploadFile.write(upload.buf, upload.currentSize);
|
| 292 | + }else |
| 293 | + { |
| 294 | + DBG_SERIAL.print("handleFileUpload file is not opened !!!"); |
281 | 295 | }
|
282 | 296 | } else if (upload.status == UPLOAD_FILE_END) {
|
283 | 297 | if (fsUploadFile) {
|
|
0 commit comments