- Fri May 05, 2023 12:41 pm
#96346
Sorry I am getting back here cause I got stuck....
I managed to incorporate some code to delete a file in flash, that proved to be quite simple, now I am trying to backup a file from LittleFS to PC(tablet/phone).
FYI I am using ESPAsyncWebServer, the example in FSBrowser does not and it seems I cannot use that example to get any further in this case.
My javascript: (It is a modal popup, the actual ajax call is the $.GET statement, I also tried POST, no dice.... Further this is a migration from a Linux server, no actual PHP is used here). I try to not use String variables as it messes up the memory usage.
Code: Select all// BackupFilehandler Send flash file to host (PC, Tablet, Phone))
function BackupFilehandler() {
var fullfilepath = filedir+document.getElementById("edittxtFilename").value;
while (document.getElementById("editdialogtable").rows.length > 5)
document.getElementById("editdialogtable").deleteRow(-1); //delete last row
document.getElementById("editpath").innerHTML = filedir;
document.getElementById("edittxtFilename").value = "";
$.get("php/BackupFile.php", {filename:fullfilepath},
function(response,status) { // Required Callback Function
// alert("*----Received Data----*\n\nResponse : " + response+"\n\nStatus : " + status);
//"response" receives - whatever written in echo of above PHP script.
});
The ESP8266 snippet:
Code: Select all editmodal.style.display = "none";
}
//***************************************************************************
// php/BackupFile.php
// Opens filedialog to host, copies flash file to host PC,Tablet,Phone
server.on("/php/BackupFile.php", HTTP_GET, [](AsyncWebServerRequest *request){
// This call has the filepath as parameter.
int nrofbytes;
char fullpath[50], filename[40];
int paramsNr = request->params();
AsyncWebParameter* p = request->getParam(0);
strcpy(fullpath, "/syx/");
p->value().toCharArray(filename,40);
strcat(fullpath, filename);
Serial.printf("Backing up %s .....\n", fullpath);
request->send(LittleFS, fullpath, "text/html", true);
});
//***************************************************************************
In this code the file from Flash (LittleFS) is sent to the browser. I read that the 'true' parameter (in the request->send) would trigger the browser's 'download file' popup, However, nothing happens in my browser. If I uncomment the 'alert' statement in the javascript I do see data coming to the browser (it is binary data BTW).
Small steps..... Next would be to upload something from PC/Tablet/Phone to the flash from ESP8266. I guess I need help there too, but let met 1st solve the backup issue....
Thanks again for your help.