diff --git a/pages/api/documents/download/[id].js b/pages/api/documents/download/[id].js index 2d740e8c..4acc9afa 100644 --- a/pages/api/documents/download/[id].js +++ b/pages/api/documents/download/[id].js @@ -42,27 +42,36 @@ export default async function ApiProxy(req, res) { var docRef = req.query; - console.log(docRef.id); - 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 .get( WEBAPI_URL + queryUrl, // + hashAPIPath(queryUrl), - azureHeadersPaged(token.access_token) + configDocument(token.access_token) ) .then((response) => { - console.log(response.headers); - res.status(200); res.setHeader( - "Content-disposition", + "content-disposition", "attachment; filename=" + response.headers["content-disposition"].split( "filename=" )[1] ); - res.end(response.data); + res.status(200).send(response.data); }) .catch(({ err }) => { res.status(400).json(err);