use part body when writing to file

This commit is contained in:
Luna 2021-04-10 15:29:36 -03:00
parent 1a3c1e354f
commit a44af53a87
1 changed files with 20 additions and 16 deletions

View File

@ -214,23 +214,27 @@ 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);
var image_path_buffer: [512]u8 = undefined;
const image_path = try std.fmt.bufPrint(
&image_path_buffer,
"{s}/{s}.jpg",
.{ images_dir_path, image_id },
);
const image_file = try std.fs.cwd().createFile(image_path, .{});
try image_file.writer().writeAll(part.body);
try response.writer().writeAll(image_path);
return;
}
var image_id_buffer: [256]u8 = undefined;
const image_id = generateImageId(&image_id_buffer);
var image_path_buffer: [512]u8 = undefined;
const image_path = try std.fmt.bufPrint(
&image_path_buffer,
"{s}/{s}.jpg",
.{ images_dir_path, image_id },
);
const image_file = try std.fs.cwd().createFile(image_path, .{});
try image_file.writer().writeAll(request.body);
try response.writer().writeAll(image_path);
}
fn fetchFile(response: *http.Response, request: http.Request, filename: []const u8) !void {