1
router.get('/ts/:streamId/:ts',  (req, res, next)=> {
    var streamId = req.params["streamId"];
    var ts = req.params["ts"];
    var url = "http://192.168.0.193/hls/27f73cdf-c565-4328-a172-d23b1118e312/playout9.ts"

    axios.create({
        headers: { 'Authorization': 'Basic ' + req.session.bearer }
    }).get(url)
    .then(response => {
        res.end(response.data);
    });
});

I can download the file provided by the url from the browser and play it in the vlc player.

but when I use res.end(response.data); in my node.js server to forward, I cannot play the forwarded file, but it has a content size of about 1600KB.

I also referred to the following article and tried to edit content-type, but it didn't work: nodejs api does not forward response which received from another service

Any ideas are greatly appreciated.

neslxzhen
  • 75
  • 1
  • 9
  • might want to look into just piping response to res, `response.data.pipe(res)`, [see dupe](https://stackoverflow.com/questions/54972716/passing-response-from-api-as-response-from-my-node-server-throws) – Lawrence Cherone Jun 01 '21 at 02:38
  • I tried `res.send(response.data);` too – neslxzhen Jun 01 '21 at 02:42
  • @LawrenceCherone you're right. After I modify `axios`, I can use `response.data.pipe(res)` to get images. Please post your answer so that I can choose you as the best answer. – neslxzhen Jun 01 '21 at 03:10

1 Answers1

0

Following the comment of Lawrence Cherone, I replace res.end(response.data); to response.data.pipe(res).

neslxzhen
  • 75
  • 1
  • 9