0

Currently I have two node.js servers connected (server1 & server2). I'm trying to get an audio file (.wav) that is saved on server1 to server2 and save it as a file on server2. I have it setup right now using mediaserver.

On server1...

ms = require('mediaserver');

app.get(/audio, function(req, res){
  ms.pipe(req, res, "/example.wav");
});

This works when I try to receive it with a standard html file using

<audio controls>
    <source src="/audio" type="audio/wav">
    Your browser does not support the audio element.
</audio>

How would I receive it and save it on server2, though. I've tried without success to write it like it was a binary file using

axios
  .get('/audio', {})
  .then(res => {
    fs.writeFile('received.wav', res.data, function(err) {
      // etc
    });
  })

Also, it may be of note that it is a 2 channel audio file with a rate of 16000.

  • Would using [res.download()](https://www.geeksforgeeks.org/express-js-res-download-function/) on the host server (with the audio file) not be a better option? – Delta Feb 03 '22 at 03:28
  • Wouldn't res.download() be used to save the audio file from the server1 side and not server2? Replacing fs.writeFile with res.download isn't recognized as a function. – Vikings1028 Feb 03 '22 at 17:12

0 Answers0