adjusted header to fix download

This commit is contained in:
2022-01-28 19:46:31 +00:00
parent 4074ed863a
commit 6b17681212
+17 -8
View File
@@ -42,27 +42,36 @@ export default async function ApiProxy(req, res) {
var docRef = req.query; var docRef = req.query;
console.log(docRef.id);
var queryUrl = "documents/download/" + docRef.id + "?hash=" + docRef.hash; var queryUrl = "documents/download/" + docRef.id + "?hash=" + docRef.hash;
console.log(WEBAPI_URL + queryUrl); const configDocument = (access_token) => {
return {
headers: {
"OData-MaxVersion": "4.0",
"OData-Version": "4.0",
"Accept": "application/json",
"Prefer": 'odata.include-annotations="*",return=representation',
"Content-Type": "application/json",
"Authorization": "Bearer " + access_token,
},
responseType: "arraybuffer",
};
};
return axios return axios
.get( .get(
WEBAPI_URL + queryUrl, // + hashAPIPath(queryUrl), WEBAPI_URL + queryUrl, // + hashAPIPath(queryUrl),
azureHeadersPaged(token.access_token) configDocument(token.access_token)
) )
.then((response) => { .then((response) => {
console.log(response.headers);
res.status(200);
res.setHeader( res.setHeader(
"Content-disposition", "content-disposition",
"attachment; filename=" + "attachment; filename=" +
response.headers["content-disposition"].split( response.headers["content-disposition"].split(
"filename=" "filename="
)[1] )[1]
); );
res.end(response.data); res.status(200).send(response.data);
}) })
.catch(({ err }) => { .catch(({ err }) => {
res.status(400).json(err); res.status(400).json(err);