Skip to content

Commit

Permalink
fixed multi-file upload
Browse files Browse the repository at this point in the history
  • Loading branch information
renerocksai committed Sep 13, 2023
1 parent b6fd422 commit 942fb0f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions examples/bindataformpost/bindataformpost.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
};

Expand All @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/zap.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 942fb0f

Please sign in to comment.