Chat freely about anything...

User avatar
By Espradio01
#79359 Hi All

I'm hoping someone here would kindly share an example of how to list the content of spiffs on a webpage.

I am currently able to upload to spiffs.
It would be great to be able to download too (not by using the ftp server example unless it's a modified version)

I have managed to create a text file that i have written to but would like to beale to :
1. check it's there
2. Download it (or check its content on the esp's web page)

Thank you kindly

Den
User avatar
By quackmore
#79398 that's funny, I'm working on that right now ...

I'm using SDK and I'm developing a web api for this
// [GET] /api/files/ls
// [GET] /api/files/cat/:name
// [POST] /api/files/delete/:name
// [POST] /api/files/create/:name

hope this will help you (and may your comments will help me ...)
cheers

######################
listing looks like this (this is the web server receiving function, I've cut some code just for showing big view)

if ((0 == os_strcmp(parsed_req.url, "/api/files/ls")) && (parsed_req.req_method == HTTP_GET))
{

if (espfs.is_available()) // if file system is available
{
...
// count files first -> file_cnt
...
// now prepare the list
...
char *file_list = (char *)os_zalloc(32 + (file_cnt * (32 + 3)));
...
if (file_list)
{
char *tmp_ptr = file_list;
os_sprintf(file_list, "{\"files\":["); // returning results with a JSON string
...
// for listing with SPIFFS checkout SPIFFS using
// the following uses my C++ wrapper
...
file_ptr = espfs.list(0);
while (file_ptr)
{
tmp_ptr = file_list + os_strlen(file_list);
if (tmp_ptr != (file_list + os_strlen("{\"files\":[")))
*(tmp_ptr++) = ',';
os_sprintf(tmp_ptr, "\"%s\"", (char *)file_ptr->name);
file_ptr = espfs.list(1);
}
tmp_ptr = file_list + os_strlen(file_list);
os_sprintf(tmp_ptr, "]}\n");
response(ptr_espconn, HTTP_OK, file_list, true);
return;
}
else
{
esplog.error("Websvr::webserver_recv - not enough heap memory\n");
return;
}
}
else
{
response(ptr_espconn, HTTP_SERVER_ERROR, "File system is not available\n", false);
return;
}
}