1
0
Fork 0
mirror of https://github.com/zigzap/zap.git synced 2025-10-20 23:24:09 +00:00

fixed multi-file upload

This commit is contained in:
Rene Schallner 2023-09-13 02:11:00 +02:00
parent b6fd422924
commit 942fb0f4a9
2 changed files with 7 additions and 6 deletions

View file

@ -12,7 +12,6 @@ const Handler = struct {
if (r.body) |body| { if (r.body) |body| {
std.log.info("Body length is {any}\n", .{body.len}); std.log.info("Body length is {any}\n", .{body.len});
std.log.info("Body is {s}\n", .{body});
} }
// check for query params (for ?terminate=true) // check for query params (for ?terminate=true)
r.parseQuery(); r.parseQuery();
@ -51,8 +50,8 @@ const Handler = struct {
std.log.debug(" filename: `{s}`\n", .{filename}); std.log.debug(" filename: `{s}`\n", .{filename});
std.log.debug(" mimetype: {s}\n", .{mimetype}); std.log.debug(" mimetype: {s}\n", .{mimetype});
std.log.debug(" contents: {any}\n", .{data}); std.log.debug(" contents: {any}\n", .{data});
files.*.deinit();
} }
files.*.deinit();
}, },
else => { else => {
// might be a string param, we don't care // might be a string param, we don't care
@ -80,6 +79,7 @@ const Handler = struct {
} else |err| { } else |err| {
std.log.err("cannot check for terminate param: {any}\n", .{err}); std.log.err("cannot check for terminate param: {any}\n", .{err});
} }
r.sendJson("{ \"ok\": true }") catch unreachable;
} }
}; };
@ -98,7 +98,8 @@ pub fn main() !void {
.on_request = Handler.on_request, .on_request = Handler.on_request,
.log = true, .log = true,
.max_clients = 10, .max_clients = 10,
.max_body_size = 1 * 1024, .max_body_size = 10 * 1024 * 1024,
.public_folder = ".",
}, },
); );
zap.enableDebugLog(); zap.enableDebugLog();

View file

@ -665,15 +665,15 @@ fn parseBinfilesFrom(a: std.mem.Allocator, o: fio.FIOBJ) !HttpParam {
const file_name_obj = fio.fiobj_ary_entry(fn_ary, i); const file_name_obj = fio.fiobj_ary_entry(fn_ary, i);
const file_mimetype_obj = fio.fiobj_ary_entry(mt_ary, i); const file_mimetype_obj = fio.fiobj_ary_entry(mt_ary, i);
var has_error: bool = false; var has_error: bool = false;
if (fio.is_invalid(file_data_obj) != 1) { if (fio.is_invalid(file_data_obj) == 1) {
std.log.debug("file data invalid in array", .{}); std.log.debug("file data invalid in array", .{});
has_error = true; has_error = true;
} }
if (fio.is_invalid(file_name_obj) != 1) { if (fio.is_invalid(file_name_obj) == 1) {
std.log.debug("file name invalid in array", .{}); std.log.debug("file name invalid in array", .{});
has_error = true; has_error = true;
} }
if (fio.is_invalid(file_mimetype_obj) != 1) { if (fio.is_invalid(file_mimetype_obj) == 1) {
std.log.debug("file mimetype invalid in array", .{}); std.log.debug("file mimetype invalid in array", .{});
has_error = true; has_error = true;
} }