-
-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial version of the file upload example.
The most important code works but the sample needs some HTML magic to be easier to understand and use.
- Loading branch information
1 parent
6aaeff9
commit 03fdcd2
Showing
27 changed files
with
1,607 additions
and
133 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
|
@@ -4,18 +4,19 @@ | |
* http://github.com/SmingHub/Sming | ||
* All files of the Sming Core are provided under the LGPL v3 license. | ||
* | ||
* WebsocketResource.cpp | ||
* HttpMultipartResource.cpp | ||
* | ||
* @author: 2017 - Slavey Karadzhov <[email protected]> | ||
* @author: 2019 - Slavey Karadzhov <[email protected]> | ||
* | ||
****/ | ||
|
||
#include "HttpMultipartResource.h" | ||
|
||
int HttpMultipartResource::setFileMap(HttpServerConnection& connection, HttpRequest& request, HttpResponse& response) | ||
{ | ||
const String& contentType = request.headers[HTTP_HEADER_CONTENT_TYPE]; | ||
if(request.method != HTTP_POST /* || !contentType.startsWith(String(MIME_FORM_MULTIPART)) */) { | ||
String contentType = request.headers[HTTP_HEADER_CONTENT_TYPE]; | ||
String mimeType = ContentType::toString(MIME_FORM_MULTIPART); | ||
if(!(request.method == HTTP_POST && contentType.startsWith(mimeType))) { | ||
return 0; | ||
} | ||
|
||
|
@@ -26,5 +27,4 @@ int HttpMultipartResource::setFileMap(HttpServerConnection& connection, HttpRequ | |
|
||
void HttpMultipartResource::shutdown(HttpServerConnection& connection) | ||
{ | ||
|
||
} |
This file contains 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 |
---|---|---|
|
@@ -4,9 +4,9 @@ | |
* http://github.com/SmingHub/Sming | ||
* All files of the Sming Core are provided under the LGPL v3 license. | ||
* | ||
* WebsocketResource.h | ||
* HttpMultipartResource.h | ||
* | ||
* @author: 2017 - Slavey Karadzhov <[email protected]> | ||
* @author: 2019 - Slavey Karadzhov <[email protected]> | ||
* | ||
****/ | ||
|
||
|
@@ -15,17 +15,28 @@ | |
#include "HttpServerConnection.h" | ||
#include "HttpResource.h" | ||
#include "WString.h" | ||
#include "WHashMap.h" | ||
|
||
typedef Delegate<void(HttpFiles&)> HttpFilesMapper; | ||
|
||
class HttpMultipartResource : public HttpResource | ||
{ | ||
public: | ||
HttpMultipartResource(const HttpFilesMapper& mapper, HttpResourceDelegate process) | ||
/** | ||
* @brief HttpResource that allows handling of HTTP file upload. | ||
* @param mapper callback that provides information where the desired upload fields will be stored. | ||
* @param complete callback that will be called after the request has completed. | ||
* @note: | ||
* On a normal computer the file uploads are usually using | ||
* temporary space on the hard disk or in memory to store the incoming data. | ||
* On an embedded device that is a luxury that we can hardly afford. | ||
* Therefore we should define a `map` that specifies explicitly | ||
* where every form field will be stored. | ||
* If a field is not specified then its content will be discarded. | ||
*/ | ||
HttpMultipartResource(const HttpFilesMapper& mapper, HttpResourceDelegate complete) | ||
{ | ||
onHeadersComplete = HttpResourceDelegate(&HttpMultipartResource::setFileMap, this); | ||
onRequestComplete = process; | ||
onRequestComplete = complete; | ||
this->mapper = mapper; | ||
} | ||
|
||
|
This file contains 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
Oops, something went wrong.