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
+6 -4
View File
@@ -107,16 +107,16 @@ export async function generateEmbeddingActivity(params: GenerateEmbeddingParams)
throw ApplicationFailure.create({ message: 'asset has no key', nonRetryable: true })
}
const { buffer: data } = await s3Service.getObject(process.env.S3_BUCKET || 'shumai', key)
const bucket = process.env.S3_BUCKET || 'shumai'
const results: GeneratedEmbedding[] = []
if (isImage) {
const { buffer: data } = await s3Service.getObject(bucket, key)
const embVec = await generateMultimodalEmbedding(ai, data, asset.mediaType)
results.push({ embedding: embVec })
} else if (isVideo) {
const tmpFile = path.join(os.tmpdir(), `video-${Date.now()}.mp4`)
fs.writeFileSync(tmpFile, data)
await s3Service.downloadToFile(bucket, key, tmpFile)
try {
const { stdout } = await execFileAsync('ffprobe', [
@@ -171,7 +171,9 @@ export async function generateEmbeddingActivity(params: GenerateEmbeddingParams)
}
}
} finally {
fs.unlinkSync(tmpFile)
if (fs.existsSync(tmpFile)) {
fs.unlinkSync(tmpFile)
}
}
}