0

I'm setting up an Express.js endpoint that would support decoding a base64 string that came from the client (camera record), which is basically an encoded webm video. The problem is that to validate this, I am trying to create a .webm video file from the encoded base64 string on the server. Unfortunately this results in a video file that cannot be played due to an error of "No video with supported format and MIME type found" (Ubuntu 18.04). I did not have any issue with any other .webm files but also the base64 URL is sure to be correct as I am using it on the cliet as the source of a element to replay what was recorded and works fine. The issue I suspect is something wrong with the code that generates the file on the server route.

import express from "express";
import multer from "multer";
import fs from "fs";
const router = express.Router();
// ...

router.post("/upload", multer().fields([]), (req, res) => {
  const formData = req.body;
  // formData.vid_string is the base64 encoded string
  fs.writeFileSync(
    "./test.webm",
    Buffer.from(formData.vid_string.split(",")[1], "base64")
  );

  res.sendStatus(200);
});

I have also tried to change fs.writeFileSync code and add "base64" as a third argument but it has the same result. Any input would be appreciated! Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.