title: RecordRTC upload video to node js server
body: <p>I am using <a href="http://recordrtc.org/RecordRTC.html" rel="nofollow">RecordRTC</a> from recording webrtc meeting. After implementing recording, when I test this application if both client are on the same system then its working fine. When I test this application on different system it isn't working fine and meeting is not recorded. </p>
  
  <p>Here this is my code from stop recording client side.</p>
  
  <pre><code>recordRTC.stopRecording(function (videoURL) {
  
              console.log('recordRTC.stopRecording Function inside');
  
              SelectedFile = recordRTC.getBlob();
              $('#uploadForm').append('#attachmentFileId', recordRTC.getBlob());
              StartUpload();
          });
  
  
      var FReader;
      var Name = "Meeting" + "_" + Date.now() + ".webm";
  
      function StartUpload()
      {
          FReader = new FileReader();
          FReader.onload = function (evnt)
          {
              socket.emit('Upload', { 'Name': Name, Data: evnt.target.result });
          }
          socket.emit('Start', { 'Name': Name, 'Size': SelectedFile.size });
      }
  
      socket.on('MoreData', function (data)
      {
          var Place = data['Place'] * 524288; //The Next Blocks Starting Position
          var NewFile; //The Variable that will hold the new Block of Data
  
          if (SelectedFile.webkitSlice)
              NewFile = SelectedFile.webkitSlice(Place, Place + Math.min(524288, (SelectedFile.size - Place)));
          else
              NewFile = SelectedFile.slice(Place, Place + Math.min(524288, (SelectedFile.size - Place)));
          FReader.readAsBinaryString(NewFile);
      });
  </code></pre>
  
  <p>Server Side Code
  I get this from <a href="http://code.tutsplus.com/tutorials/how-to-create-a-resumable-video-uploade-in-node-js--net-25445" rel="nofollow">here</a>.</p>
  
  <pre><code>socket.on('Start', function (data) { //data contains the variables that we passed through in the html file
          var Name = data['Name'];
          Files[Name] = {  //Create a new Entry in The Files Variable
              FileSize : data['Size'],
              Data     : "",
              Downloaded : 0
          }
          var Place = 0;
          try{
              var Stat = fs.statSync('Temp/' +  Name);
              if(Stat.isFile())
              {
                  Files[Name]['Downloaded'] = Stat.size;
                  Place = Stat.size / 524288;
              }
          }
          catch(er){} //It's a New File
          fs.open("Temp/" + Name, 'a', 0755, function(err, fd){
              if(err)
              {
                  console.log(err);
              }
              else
              {
                  Files[Name]['Handler'] = fd; //We store the file handler so we can write to it later
                  socket.emit('MoreData', { 'Place' : Place, Percent : 0 });
              }
          });
  });
  
  socket.on('Upload', function (data){
          var Name = data['Name'];
          Files[Name]['Downloaded'] += data['Data'].length;
          Files[Name]['Data'] += data['Data'];
          if(Files[Name]['Downloaded'] == Files[Name]['FileSize']) //If File is Fully Uploaded
          {
              fs.write(Files[Name]['Handler'], Files[Name]['Data'], null, 'Binary', function(err, Writen){
              var input = fs.createReadStream("Temp/" + Name);
              var output = fs.createWriteStream("Video/" + Name);
  
              //util.pump(readableStream, writableStream, [callback])
              //Deprecated: Use readableStream.pipe(writableStream)
              input.pipe(output);
              input.on("end", function() {
                  console.log("end");
                  fs.unlink("Temp/" + Name, function ()
                  { //This Deletes The Temporary File
                      console.log("unlink this file:",Name );
                      //socket.emit('Done', {'Image' : 'Video/' + Name + '.jpg'});
                  });
              });
          });
          }
          else if(Files[Name]['Data'].length &gt; 10485760){ //If the Data Buffer reaches 10MB
              fs.write(Files[Name]['Handler'], Files[Name]['Data'], null, 'Binary', function(err, Writen){
                  Files[Name]['Data'] = ""; //Reset The Buffer
                  var Place = Files[Name]['Downloaded'] / 524288;
                  var Percent = (Files[Name]['Downloaded'] / Files[Name]['FileSize']) * 100;
                  socket.emit('MoreData', { 'Place' : Place, 'Percent' :  Percent});
              });
          }
          else
          {
              var Place = Files[Name]['Downloaded'] / 524288;
              var Percent = (Files[Name]['Downloaded'] / Files[Name]['FileSize']) * 100;
              socket.emit('MoreData', { 'Place' : Place, 'Percent' :  Percent});
          }
      });
  </code></pre>
  
  <p>If both clients are on same machine/system its working fine, but if both clients are on different system then meeting is not recorded.</p>