How to Create a Robust Video Uploading System Using Cloudflare Workers and R2 Storage?

I’m currently working on a project where I initiate a mock interview and allow users to record their responses. The recording process involves sending chunks of data every second through websockets using Cloudflare Workers. Once the user stops the recording, I combine all the received chunks (ArrayBuffer) and proceed to upload the video to R2. However, I have encountered a couple of significant issues:

  1. In several instances, the uploaded video file turns out to be corrupt. Ideally, the file format should be either mp4 or webm.
  2. Sometimes, the video fails to save altogether, resulting in a loss of data.

I am keen on enhancing the reliability and efficiency of this system to ensure a seamless user experience, where every user can successfully save and upload their video files without any glitches or data corruption. Could you provide insights or suggestions on how I can modify my existing setup or employ new strategies to build a more robust and fail-safe system? Additionally, if you could recommend any tools or technologies that can facilitate this improvement, it would be highly beneficial. I’m eager to create a solution where the video upload functionality works flawlessly for every user. Any advice would be greatly appreciated.