-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Handle large octet-stream (master branch) #9440
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
172083f
Handle large octet-stream
nathannau 4587fc6
Add exemple Upload Huge File
nathannau 5102d32
Remove unuse function printDirectory
nathannau 0973933
Fix upload path
nathannau 94a3a7d
Simplify and generalize the body parsing.
nathannau 23493b8
Create .skip.esp32h2
me-no-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Upload Huge File To SD Over Http | ||
|
||
This project is an example of an HTTP server designed to facilitate the transfer of large files using the PUT method, in accordance with RFC specifications. | ||
|
||
### Example cURL Command | ||
|
||
```bash | ||
curl -X PUT -T ./my-file.mp3 http://esp-ip/upload/my-file.mp3 | ||
``` | ||
|
||
## Resources | ||
|
||
- RFC HTTP/1.0 - Additional Request Methods - PUT : [Link](https://datatracker.ietf.org/doc/html/rfc1945#appendix-D.1.1) |
88 changes: 88 additions & 0 deletions
88
libraries/WebServer/examples/UploadHugeFile/UploadHugeFile.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#include <WiFi.h> | ||
#include <WiFiClient.h> | ||
#include <WebServer.h> | ||
#include <uri/UriRegex.h> | ||
#include <SD.h> | ||
|
||
const char* ssid = "**********"; | ||
const char* password = "**********"; | ||
|
||
WebServer server(80); | ||
|
||
File rawFile; | ||
void handleCreate() { | ||
server.send(200, "text/plain", ""); | ||
} | ||
void handleCreateProcess() { | ||
String path = "/" + server.pathArg(0); | ||
HTTPRaw& raw = server.raw(); | ||
if (raw.status == RAW_START) { | ||
if (SD.exists((char *)path.c_str())) { | ||
SD.remove((char *)path.c_str()); | ||
} | ||
rawFile = SD.open(path.c_str(), FILE_WRITE); | ||
Serial.print("Upload: START, filename: "); | ||
Serial.println(path); | ||
} else if (raw.status == RAW_WRITE) { | ||
if (rawFile) { | ||
rawFile.write(raw.buf, raw.currentSize); | ||
} | ||
Serial.print("Upload: WRITE, Bytes: "); | ||
Serial.println(raw.currentSize); | ||
} else if (raw.status == RAW_END) { | ||
if (rawFile) { | ||
rawFile.close(); | ||
} | ||
Serial.print("Upload: END, Size: "); | ||
Serial.println(raw.totalSize); | ||
} | ||
} | ||
|
||
void returnFail(String msg) { | ||
server.send(500, "text/plain", msg + "\r\n"); | ||
} | ||
|
||
void handleNotFound() { | ||
String message = "File Not Found\n\n"; | ||
message += "URI: "; | ||
message += server.uri(); | ||
message += "\nMethod: "; | ||
message += (server.method() == HTTP_GET) ? "GET" : "POST"; | ||
message += "\nArguments: "; | ||
message += server.args(); | ||
message += "\n"; | ||
for (uint8_t i = 0; i < server.args(); i++) { | ||
message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; | ||
} | ||
server.send(404, "text/plain", message); | ||
} | ||
|
||
void setup(void) { | ||
Serial.begin(115200); | ||
|
||
while (!SD.begin()) delay(1); | ||
Serial.println("SD Card initialized."); | ||
|
||
WiFi.mode(WIFI_STA); | ||
WiFi.begin(ssid, password); | ||
|
||
while (WiFi.status() != WL_CONNECTED) { | ||
delay(500); | ||
Serial.print("."); | ||
} | ||
Serial.print("Connected to "); | ||
Serial.println(ssid); | ||
Serial.print("IP address: "); | ||
Serial.println(WiFi.localIP()); | ||
|
||
server.on(UriRegex("/upload/(.*)"), HTTP_PUT, handleCreate, handleCreateProcess); | ||
server.onNotFound(handleNotFound); | ||
server.begin(); | ||
Serial.println("HTTP server started"); | ||
|
||
} | ||
|
||
void loop(void) { | ||
server.handleClient(); | ||
delay(2);//allow the cpu to switch to other tasks | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.