How to save blob as webm on node.js

I am recording a video in chrome using RecordRTC.js and then sending the generated blob to the node.js server using enctype = 'multipart / form-data'.

When I send post request converting blob as dataURL,

Content-Disposition: form-data; name="name"

Content-Disposition: form-data; name="type"

Content-Disposition: form-data; name="contents"



It works fine. Except when the data is large, the video is not saved properly. Perhaps because the whole content cannot be transferred due to the large size.

So, I tried to send blob as input type file, but the saved video seems to be corrupted as it won't play.

The blob sent when printed on the server looks something like this:

Eߣ@ B  B  B  B B @webmB  B  S g fI f@(*ױ@B@M @whammyWA@whammyD @žT k@5 @2ׁsŁ  " ...


Server side code:

function upload(response, file) {

   var fileRootName ='.').shift(),
     fileExtension ='.').pop(),
     filePathBase = upload_dir + '/',
     fileRootNameWithBase = filePathBase + fileRootName,
     filePath = fileRootNameWithBase + '.' + fileExtension,
     fileID = 2,

   while (fs.existsSync(filePath)) {
     filePath = fileRootNameWithBase + '(' + fileID + ').' + fileExtension;
     fileID += 1;

   file.contents = file.contents.split(',').pop(); // removed this when sent contents as blob

   fileBuffer = new Buffer(file.contents, "base64");

   fs.writeFileSync(filePath, fileBuffer);


What am I missing? How can I write the content of the blob in a file so that it can be saved as a webm file?


source to share

1 answer

In my case I am doing as below and its working:

    new Buffer(encoder.compile(true)),
        if (e) console.log('fs.writeFile error '+e);


Failure to specify "base64" when creating the file (and not in the buffer) may have been wrong. As you can see, I am using whammy on the server side (just pushing each frame to the encoder).

encoder = new Whammy.Video();
encoder.add(data.image, data.duration);


Hope this helps you!



All Articles