fix: use multipart upload for attachments to resolve chunk size error (#368)

This commit is contained in:
Henry
2026-02-07 22:42:38 +00:00
committed by GitHub
parent 24e283e22c
commit 97cfd60b59
3 changed files with 314 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { PutObjectCommand } from "@aws-sdk/client-s3";
import { Upload } from "@aws-sdk/lib-storage";
import { createNextApiContext } from "@kan/api/trpc";
import * as cardRepo from "@kan/db/repository/card.repo";
@@ -90,16 +90,19 @@ export default withRateLimit(
const client = createS3Client();
// Upload the file to S3
await client.send(
new PutObjectCommand({
const upload = new Upload({
client,
params: {
Bucket: bucket,
Key: s3Key,
Body: req,
ContentType: contentType,
ContentLength: contentLength,
}),
);
},
leavePartsOnError: false,
});
await upload.done();
// Create attachment record and log activity
const attachment = await cardAttachmentRepo.create(db, {