We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
printDirectory() in the SDWebserver.ino example produces invalid json.
When a directory contains no files or directories, printDirectory produces only the end of array marker:
]
Better to produce an empty array:
[]
server.sendContent() appears to be dog-slow. server.send() is faster by at least 1 second.
Proposal:
void printDirectory() { if(!server.hasArg("dir")) return returnFail("BAD ARGS"); String path = server.arg("dir"); if(path != "/" && !SD.exists((char *)path.c_str())) return returnFail("BAD PATH"); File dir = SD.open((char *)path.c_str()); path = String(); if(!dir.isDirectory()){ dir.close(); return returnFail("NOT DIR"); } dir.rewindDirectory(); WiFiClient client = server.client(); String output = "["; for (int cnt = 0; true; ++cnt) { File entry = dir.openNextFile(); if (!entry) break; if (cnt > 0) output += ','; output += "{\"type\":\""; output += (entry.isDirectory()) ? "dir" : "file"; output += "\",\"name\":\""; output += entry.name(); output += "\""; output += "}"; entry.close(); } output += "]"; server.send(200, "text/json", output); dir.close(); }
The text was updated successfully, but these errors were encountered:
#406
what you suggest will break if folder has many files and content get's large.
Sorry, something went wrong.
No branches or pull requests
printDirectory() in the SDWebserver.ino example produces invalid json.
When a directory contains no files or directories, printDirectory produces only the end of array marker:
]
Better to produce an empty array:
server.sendContent() appears to be dog-slow.
server.send() is faster by at least 1 second.
Proposal:
The text was updated successfully, but these errors were encountered: