Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Fix file writing and S3 upload handling in ffmpeg-video

Richie McIlroyc628e4355a97
diff --git a/apps/media-server/src/lib/ffmpeg-video.ts b/apps/media-server/src/lib/ffmpeg-video.ts
index e8c0db9a3..192912221 100644
--- a/apps/media-server/src/lib/ffmpeg-video.ts
+++ b/apps/media-server/src/lib/ffmpeg-video.ts
@@ -170,7 +170,8 @@ export async function downloadVideoToTemp(
throw new Error("No response body");
}
- await Bun.write(tempFile.path, response.body);
+ const arrayBuffer = await response.arrayBuffer();
+ await Bun.write(tempFile.path, arrayBuffer);
const fileHandle = file(tempFile.path);
const fileSize = fileHandle.size;
@@ -412,16 +413,21 @@ export async function generateThumbnail(
}
export async function uploadToS3(
- data: Uint8Array | Blob | ReadableStream<Uint8Array>,
+ data: Uint8Array | Blob,
presignedUrl: string,
contentType: string,
): Promise<void> {
+ const blob =
+ data instanceof Blob
+ ? data
+ : new Blob([data.buffer as ArrayBuffer], { type: contentType });
const response = await fetch(presignedUrl, {
method: "PUT",
headers: {
"Content-Type": contentType,
+ "Content-Length": blob.size.toString(),
},
- body: data,
+ body: blob,
});
if (!response.ok) {