In detail, here is what I have to achieve.
I have an api (python) which gives zip of several pdf files and the response content type is 'application/octet-stream' and content-disposition is 'attachment;filename=5omefilename.zip'. I run this api call from browser / postman then I can save the attachment as zip file and can unzip it properly. This part is working.
Now I have another composite layer api in node/ts which calls the above api and just have to forward the response and headers to UI (UI will call this node api to get the zip)
so, in the node api code I am just getting the response body and headers from python api and setting the same as response and headers. But when I run the node api, the attached zip file which I can download can not be opened. It says it corrupted
I see that the body (binary code of octet stream) is different between both api calls. (including bite size)
Somewhere when I am passing the response body from one api to another it's getting corrupted.
Node api code:
//call to python api
// apiResponse object will have headers and result (body content)
const apiResponse = await manager.fetchDoc(Id);
res.setHeader('content-type', apiResponse.headers["content-type"]);
res.setHeader('content-disposition', apiResponse.headers["content-disposition"]);
res.send(apiResponse.result);
async fetchDoc(Id) {
let response = { error: null, result: null, headers: null };
result = await request(options);
let contentType = result.headers["content-type"];
if (method === 'GET' && contentType!="application/octet-stream") {
logger.info(`GET method result.headers: ${JSON.stringify(result.headers, null, 4)}`);
response.result = JSON.parse(result.body)
} else {
logger.info(`either POST or GET method with octet-stream`);
response.result = result.body;
}
response.headers = result.headers;
}