fix(s3): stream downloadToFile and putObject to prevent OOM on large files (#392)

* fix(s3): stream downloadToFile and putObject to prevent OOM on large files

* fix(agent): preserve file MIME detection on download_asset and align local download directory creation
This commit is contained in:
Yiling-J
2026-09-07 19:33:13 +08:00
committed by GitHub
parent 67b767f1e8
commit f62df9555a
7 changed files with 272 additions and 56 deletions
+3 -3
View File
@@ -39,10 +39,10 @@ export const localUploadRoute = new Hono().put(
if (!file) {
return c.text('No file uploaded', 400)
}
const buffer = Buffer.from(await file.arrayBuffer())
const size = file.size
finalContentType = file.type || 'application/octet-stream'
await s3Service.putObject(bucket, key, buffer, size, finalContentType)
const payload =
typeof file.stream === 'function' ? file.stream() : Buffer.from(await file.arrayBuffer())
await s3Service.putObject(bucket, key, payload, file.size, finalContentType)
} else {
const body = c.req.raw.body ?? (await c.req.arrayBuffer())
await s3Service.putObject(bucket, key, body, contentLength, finalContentType)