When I use GET, everything works fine. However, I struggle to use POST to achieve the same effect. Here are the code I have tried:
1.
app.post("/download", function (req, res) {
res.download("./path");
});
2.
app.post("/download", function (req, res) {
res.attachment("./path");
res.send("ok");
});
3.
app.post("/download", function (req, res) {
res.sendFile("./path");
});
None of them work. What is the correct way to do this?
EDIT: I submit a POST request through a HTML form to /download
. ./path
is a static file. When I use code in method 1, I can see the correct response header and response body in the developer tool. But the browser does not prompt a download.
Aucun commentaire:
Enregistrer un commentaire