MCPcopy Create free account
hub / github.com/SmingHub/Sming / onUpload

Function onUpload

samples/HttpServer_FirmwareUpload/app/application.cpp:27–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25}
26
27int onUpload(HttpServerConnection& connection, HttpRequest& request, HttpResponse& response)
28{
29 ReadWriteStream* file = request.files["firmware"];
30 auto otaStream = static_cast<OtaUpgradeStream*>(file);
31 if(otaStream == nullptr) {
32 debug_e("Something went wrong with the file upload");
33 return 1;
34 }
35
36 if(response.isSuccess() && !otaStream->hasError()) {
37 // defer the reboot by 1000 milliseconds to give time to the web server to return the response
38 System.restart(1000);
39
40 response.sendFile("restart.html");
41 response.headers[HTTP_HEADER_CONNECTION] = "close";
42
43 return 0;
44 }
45
46 response.code = HTTP_STATUS_BAD_REQUEST;
47 response.setContentType(MIME_HTML);
48 String html = "<H2 color='#444'>" + toString(otaStream->errorCode) + "</H2>";
49 response.headers[HTTP_HEADER_CONTENT_LENGTH] = html.length();
50 response.sendString(html);
51
52 return 0;
53}
54
55void fileUploadMapper(HttpFiles& files)
56{

Callers

nothing calls this directly

Calls 8

isSuccessMethod · 0.80
hasErrorMethod · 0.80
setContentTypeMethod · 0.80
toStringFunction · 0.50
restartMethod · 0.45
sendFileMethod · 0.45
lengthMethod · 0.45
sendStringMethod · 0.45

Tested by

no test coverage detected