Skip to content
New issue

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

Serve it over HTTP #16

Open
maxdd opened this issue Aug 31, 2022 · 1 comment
Open

Serve it over HTTP #16

maxdd opened this issue Aug 31, 2022 · 1 comment

Comments

@maxdd
Copy link

maxdd commented Aug 31, 2022

Hello,
how would you serve it over HTTP?
Is there an example?
I don't think serving the log directly from SPIFFS into the WebServer handler function is the appropriate method mainly because there is no possibility to store "\n" or "\r".

    server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
      request->send(SPIFFS, ....);
    });

so serving the file as text to be read from the browser would be tricky to read.
I think the same applies also by using this idea with the downside that the log is flushed so my understanding is that it will be removed from SPIFFS which is not always ideal

    server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
      logger.flush(); //set log_string via flusher handler
      request->send(200, "text/text", log_string);
    });

What's the reason why "\n" cannot be used in the text?
Regards,

@fabianoriccardi
Copy link
Owner

Hi,
I think that the best way to download without deleting the log from the filesystem is using streamFile(..):

 server.sendHeader("Content-Type", "text/text");
 server.sendHeader("Content-Disposition", "attachment; filename="+filename);
 server.sendHeader("Connection", "close");
 server.streamFile(downloadFile, "application/octet-stream");

or calling the send(..) function that takes a general stream. This is the prototype on ESP8266:

 void WebServer::send(int code, const char* content_type, Stream* stream, size_t content_length = 0);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants