NodeJS: Converting uploaded video from Base64 to .mov file has problems

498 views Asked by At

I have a form which a user uploads a .mov file. In the browser, this is converted into a Base64 string which is then stored in a text input as a value for that input. When the form is submitted, the server takes the value from the text input and uses writeFile() to store it as a file on the server. I need this to be able to play like a regular video, but instead, it is downloaded to my local machine. Below you can find examples.

What I want the file to behave like:

Correct behavior

What the created file behaves like (gets downloaded):

Incorrect Behavior (uploaded file)

Here is the code I use to turn the Base64 string into a file. This is a function within an express API endpoint.

var base64DataVideo = the base64 string of the video.

 var base64DataVideo = req.body.text[5].replace(`data:video/quicktime;base64,`, "");
var videoPath = "./public/assets/Videos/"+ req.body.text[0].replace(" ", "-")+req.body.number[1]+".mov"


fs.writeFile(videoPath, base64DataVideo, 'base64', function(err) {
  console.log(err);

});

0

There are 0 answers