- Mon Dec 03, 2018 12:46 pm
#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;
}
}
https://github.com/quackmore