Arduino icon indicating copy to clipboard operation
Arduino copied to clipboard

SDWebServer Example - How to use the upload code to upload a file to SD card ?

Open SrikanthBala opened this issue 10 years ago • 1 comments

Hardware Hardware: ESP-12E on Node MCU 1.0 Core Version: 2.3.0

Hi guys. In need of some help. The SDWebServer Example works well but I am unable to understand how to use the upload part in the example, to upload a file to the root of the SD card using a HTML. I would basically wish to upload a file to my SD card which would overwrite the existing file of the same name. The code under 'upload' seems to do exactly this but what do I put in the HTML file to activate this ?

void SDhandleFileUpload(void){ if(server.uri() != "/edit") return; HTTPUpload& upload = server.upload(); if(upload.status == UPLOAD_FILE_START){ if(SD.exists((char *)upload.filename.c_str())) SD.remove((char *)upload.filename.c_str()); uploadFile = SD.open(upload.filename.c_str(), FILE_WRITE); Serial.print("Upload: START, filename: "); Serial.println(upload.filename); } else if(upload.status == UPLOAD_FILE_WRITE){ if(uploadFile) uploadFile.write(upload.buf, upload.currentSize); Serial.print("Upload: WRITE, Bytes: "); Serial.println(upload.currentSize); } else if(upload.status == UPLOAD_FILE_END){ if(uploadFile) uploadFile.close(); Serial.print("Upload: END, Size: "); Serial.println(upload.totalSize); } }

Kindly point me in the right drirection

SrikanthBala avatar Sep 27 '16 10:09 SrikanthBala

@SrikanthBala look at the FSBrowser example, specifically the editor. Off-topic, closing per #3655 .

devyte avatar Oct 12 '17 06:10 devyte