download link with filename from api

This commit is contained in:
2021-10-08 11:10:15 +01:00
parent ab62e339aa
commit e19efb8b62
7 changed files with 76 additions and 55 deletions
+9 -6
View File
@@ -61,7 +61,7 @@ const getSASToken = () => {
};
export default async function ApiProxy(req, res) {
console.log(req.method);
//console.log(req.method);
var data = JSON.stringify(req.body);
const SASToken = getSASToken();
@@ -121,18 +121,21 @@ export default async function ApiProxy(req, res) {
: config
)
.then((response) => {
// console.log(response);
res.statusCode = 200;
if (hasDocument) {
res.setHeader("Content-Type", "text/plain");
res.setHeader(
"Content-disposition",
"attachment; filename=" +
response.headers["content-disposition"].split(
"filename="
)[1]
);
res.end(response.data);
} else {
res.setHeader("Content-Type", "application/json");
res.setHeader("Cache-Control", "max-age=1800000");
// res.setHeader("Cache-Control", "max-age=1800000");
res.end(JSON.stringify(response.data));
}
//console.log("response data", response.data);
resolve();
})
.catch((error) => {