Chat freely about anything...

User avatar
By ArjenV
#96288 I tried the python littlefs tools, this will not do, it is not user-friendly.
I then studied the FS_browser example, even uploaded it to a NodeMCU. This is way to elaborate for my application, it would more then double the code.

So again I ask the question:

And to be more detailed, I store data in a certain directory (/syx/). I'd like to backup the files under the /syx/ directory. I do not have to pick a particular file, just download all files to my PC/phone/tablet will do. Maybe first zip it or pack it to one file and then download it. However, I did not find a 'make a zip (or pack) from littleFS files' library or example.

So pls direct me to a solution. I am not a newbie, but have little experience with this particular case.
User avatar
By btidey
#96294 Compressing files to a zip format requires large amounts of RAM so is not a good fit to microcontrollers with relatively small amounts of RAM available.

If you need to group files together then you could use the tar format and there is code available to do that.
For example, https://github.com/rxi/microtar

If you want to download just a fixed file then you can still use the methods available in FSBrowser and just leave out all the stuff you don't want. The key part here is the handleFileRead function. With e fixed filename that can be simplified further and triggered by a simple GET url
User avatar
By ArjenV
#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.