aboutsummaryrefslogtreecommitdiff
path: root/src/routes/api/profile/image/upload.zig
blob: db140d483b218d4c87f8d6ad33944a37d9162cd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const std = @import("std");

const memora = @import("memora");
const Context = memora.Context;
const Storage = memora.Storage;

pub const access = .users;

pub fn post(ctx: *Context) !void {
    const name = ctx.request.head.target["/api/profile/image/upload/".len..];
    if (ctx.request.head.content_length) |length| {
        var buffer: [1024]u8 = undefined;
        const reader = try ctx.request.readerExpectContinue(&buffer);

        try Storage.User.set_image(ctx.storage, name, reader, length);

        ctx.response.headers.content_type = "image/jpeg";
    }
}