res.sendFile send static file + object

前端 未结 2 490
悲&欢浪女
悲&欢浪女 2021-01-20 09:08

I have to serve a html file with express, but also want to send an object along with the response. How can i send both - the detail.html and the object \'car\' - and how can

2条回答
  •  春和景丽
    2021-01-20 09:34

    res.sendFile has to set some special headers (Content-Disposition paired with a Content-Type) so the browser will understand that an attachment its comming and based on the file type and browser either show the save dialog or open the file

    What you could do is send the car object as a json with res.json and in the frontend check that the json was fetched so you can hit a second endpoint which will trigger the download

提交回复
热议问题