mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-18 10:59:45 +00:00
Add form-upload example
This commit is contained in:
1 parent
41c1e0f08d
commit
4dbb2da78f
7 files changed
+116
-36
No files matched your search
+1
-21
@@ -846,28 +846,8 @@ Parse the multipart chunk in the `body` at a given `offset`. An initial
|
||||
`offset` should be 0. Fill up parameters in the provided `part`, which could be
|
||||
NULL. Return offset to the next chunk, or 0 if there are no more chunks.
|
||||
|
||||
Usage example:
|
||||
See `form-upload` example for a usage example.
|
||||
|
||||
```c
|
||||
static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
||||
if (ev == MG_EV_HTTP_MSG) {
|
||||
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
|
||||
if (mg_http_match_uri(hm, "/upload")) {
|
||||
struct mg_http_part part;
|
||||
size_t ofs = 0;
|
||||
while ((ofs = mg_http_next_multipart(ev->body, ofs, &part)) > 0) {
|
||||
LOG(LL_INFO, ("Name: [%.*s] Filename: [%.*s] Body: [%.*s]",
|
||||
(int) part.name.len, part.name.ptr,
|
||||
(int) part.filename.len, part.filename.ptr,
|
||||
(int) part.body.len, part.body.ptr));
|
||||
}
|
||||
} else {
|
||||
struct mg_http_serve_opts opts = {.root_dir = "web_root"};
|
||||
mg_http_serve_dir(c, ev_data, &opts);
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Websocket
|
||||
|
||||
|
||||
Reference in new issue
Block a user