0

My js code :

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.write("sending two files"+"      ");
    res.writeHead(200, {'Content-Type', "video/mp4"});
    var stream = GridFile.stream(true);
    stream.pipe(res);
    res.end();
}).listen(3001, "ipaddress"); 

I'm sending two MIME types(text/plain,video/mp4) in one callback function from js file.How do I retrieve and parse the same in html ?

Can anyone please help me out regarding this ...

dev777
  • 999
  • 6
  • 17
  • 34

1 Answers1

0

You would need to do something like this, but again, I have no idea why you'd want to:

var CRLF = '\r\n';
http.createServer(function (req, res) {
  var BOUNDARY = '' + Date.now();
  res.writeHead(200, {'Content-Type': 'multipart/mixed; boundary=' + BOUNDARY });
  res.write(
    CRLF +
    '--' + BOUNDARY + CRLF +
    'Content-Type: text/html' + CRLF +
    CRLF
  );
  res.write('<html><body><p>This is the first file</p></body></html>');
  res.write(
    CRLF +
    '--' + BOUNDARY + CRLF +
    'Content-Type: video/mp4' + CRLF +
    CRLF
  );
  var stream = GridFile.stream(true);
  steam.on('end', function () {
    res.write(
      CRLF +
      '--' + BOUNDARY + '--' +
      CRLF
    )
  })
  stream.on('error', function (e) {
    console.log('stream error', e)
    res.end()
  })
  stream.pipe(res, { end: false })
}).listen(3001, "ipaddress"); 
idbehold
  • 16,833
  • 5
  • 47
  • 74
  • Hi idbehold, I had used the same code in my js file.But I'm unable to retrieve the two responses in my html page. I thing my video file is getting corrupted with the text.Can you please edit the code of how to retrieve the video and text in the html page. – dev777 Jun 17 '16 at 06:07