From 942fb0f4a916167be34d35398d48a2a03271f608 Mon Sep 17 00:00:00 2001 From: Rene Schallner Date: Wed, 13 Sep 2023 02:11:00 +0200 Subject: [PATCH] fixed multi-file upload --- examples/bindataformpost/bindataformpost.zig | 7 ++++--- src/zap.zig | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/examples/bindataformpost/bindataformpost.zig b/examples/bindataformpost/bindataformpost.zig index 441bcc5..1a60849 100644 --- a/examples/bindataformpost/bindataformpost.zig +++ b/examples/bindataformpost/bindataformpost.zig @@ -12,7 +12,6 @@ const Handler = struct { if (r.body) |body| { 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) r.parseQuery(); @@ -51,8 +50,8 @@ const Handler = struct { std.log.debug(" filename: `{s}`\n", .{filename}); std.log.debug(" mimetype: {s}\n", .{mimetype}); std.log.debug(" contents: {any}\n", .{data}); - files.*.deinit(); } + files.*.deinit(); }, else => { // might be a string param, we don't care @@ -80,6 +79,7 @@ const Handler = struct { } else |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, .log = true, .max_clients = 10, - .max_body_size = 1 * 1024, + .max_body_size = 10 * 1024 * 1024, + .public_folder = ".", }, ); zap.enableDebugLog(); diff --git a/src/zap.zig b/src/zap.zig index 4c21e3f..925a6e6 100644 --- a/src/zap.zig +++ b/src/zap.zig @@ -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_mimetype_obj = fio.fiobj_ary_entry(mt_ary, i); 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", .{}); 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", .{}); 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", .{}); has_error = true; }