use part body when writing to file
This commit is contained in:
parent
1a3c1e354f
commit
a44af53a87
1 changed files with 20 additions and 16 deletions
10
src/main.zig
10
src/main.zig
|
@ -214,8 +214,10 @@ fn uploadFile(response: *http.Response, request: http.Request) !void {
|
|||
var hzzp_buffer: [1024]u8 = undefined;
|
||||
|
||||
while (try multipart.next(&hzzp_buffer)) |part| {
|
||||
std.log.info("part: {}", .{part});
|
||||
}
|
||||
std.log.info(
|
||||
"got part from multipart request! name='{s}' filename='{s}' content_type='{s}' length={d}",
|
||||
.{ part.disposition.name, part.disposition.filename, part.content_type, part.body.len },
|
||||
);
|
||||
|
||||
var image_id_buffer: [256]u8 = undefined;
|
||||
const image_id = generateImageId(&image_id_buffer);
|
||||
|
@ -228,9 +230,11 @@ fn uploadFile(response: *http.Response, request: http.Request) !void {
|
|||
);
|
||||
|
||||
const image_file = try std.fs.cwd().createFile(image_path, .{});
|
||||
try image_file.writer().writeAll(request.body);
|
||||
try image_file.writer().writeAll(part.body);
|
||||
|
||||
try response.writer().writeAll(image_path);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
fn fetchFile(response: *http.Response, request: http.Request, filename: []const u8) !void {
|
||||
|
|
Loading…
Reference in a new issue