mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-25 12:04:47 +00:00
Allow user specify file in mg_http_upload
This commit is contained in:
1 parent
fa5aa308bc
commit
e0668bc1c0
9 files changed
+80
-62
No files matched your search
@@ -10,16 +10,7 @@ static void cb(struct mg_connection *c, int ev, void *ev_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")) {
|
||||
char path[80], name[64];
|
||||
mg_http_get_var(&hm->query, "name", name, sizeof(name));
|
||||
mg_snprintf(path, sizeof(path), "/tmp/%s", name);
|
||||
if (name[0] == '\0') {
|
||||
mg_http_reply(c, 400, "", "%s", "name required");
|
||||
} else if (!mg_path_is_sane(path)) {
|
||||
mg_http_reply(c, 400, "", "%s", "invalid path");
|
||||
} else {
|
||||
mg_http_upload(c, hm, &mg_fs_posix, path, 99999);
|
||||
}
|
||||
mg_http_upload(c, hm, &mg_fs_posix, "/tmp", 99999);
|
||||
} else {
|
||||
struct mg_http_serve_opts opts = {.root_dir = "web_root"};
|
||||
mg_http_serve_dir(c, ev_data, &opts);
|
||||
|
||||
@@ -17,7 +17,7 @@ var sendFileData = function(name, data, chunkSize) {
|
||||
var sendChunk = function(offset) {
|
||||
var chunk = data.subarray(offset, offset + chunkSize) || '';
|
||||
var opts = {method: 'POST', body: chunk};
|
||||
var url = '/upload?offset=' + offset + '&name=' + encodeURIComponent(name);
|
||||
var url = '/upload?offset=' + offset + '&file=' + encodeURIComponent(name);
|
||||
var ok;
|
||||
setStatus(
|
||||
'Uploading ' + name + ', bytes ' + offset + '..' +
|
||||
|
||||
Reference in new issue
Block a user