forked from me-no-dev/ESPAsyncWebServer
-
Notifications
You must be signed in to change notification settings - Fork 69
Closed
Closed
Copy link
Labels
Description
Platform
ESP32
IDE / Tooling
Arduino (IDE/CLI)
What happened?
In version v3.7.9, a request is played in the browser (very small video file from LittleFS, SD card, etc.).
In version v3.7.10, the same request downloads the file, a problem for me, I need the browser to play the file (very small video file).
Stack Trace
AsyncWebServerResponse *response = request->beginResponse(LittleFS, path, contentType, false);
if (contentType == F("image/jpeg") || contentType == F("video/mp4")) {
response->addHeader("Cache-Control", "public, max-age=31536000");
}
request->send(response);
It's downloading, not playing the video in v3.7.10.
v3.7.9 is OK.
Minimal Reproductible Example (MRE)
#include <Arduino.h>
#if defined(ESP32)
#include <WiFi.h>
#include <AsyncTCP.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#endif
#include <ESPAsyncWebServer.h>
#include <LittleFS.h>
const char* ssid = "SSID";
const char* password = "PASSWORD";
static const char *index_htm PROGMEM = R"rawliteral(
<!DOCTYPE html>
<html>
<body>
<a href="1.mp4">Play Video</a>
<br>
<a href="esp32.jpg">Show Image</a>
</body>
</html>
)rawliteral";
static const size_t index_htmLength = strlen_P(index_htm);
static AsyncWebServer server(80);
void readFile(AsyncWebServerRequest *request) {
String path = request->url().c_str();
String contentType;
if (path.endsWith(F(".mp4"))) {
contentType = F("video/mp4");
} else if (path.endsWith(F(".jpg"))) {
contentType = F("image/jpeg");
}
File data = LittleFS.open(path.c_str(), "r");
if (!data) {
data.close();
request->send(404, F("text/plain"), F("File not found"));
return;
}
AsyncWebServerResponse *response = request->beginResponse(LittleFS, path, contentType, false);
if (contentType == F("image/jpeg") || contentType == F("video/mp4")) {
response->addHeader("Cache-Control", "public, max-age=31536000");
}
request->send(response);
}
void setup() {
Serial.begin(115200);
if (!LittleFS.begin()) {
Serial.println(F("An Error has occurred while mounting LittleFS"));
return;
}
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(F("."));
delay(1000);
}
Serial.println(WiFi.localIP());
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
request->send(200, "text/html", (uint8_t *)index_htm, index_htmLength);
});
server.onNotFound(readFile);
server.begin();
}
void loop() {
}
I confirm that:
- I have read the documentation.
- I have searched for similar discussions.
- I have searched for similar issues.
- I have looked at the examples.
- I have upgraded to the lasted version of ESPAsyncWebServer (and AsyncTCP for ESP32).
Copilot