'Node.js Request pass response of api call as get response
I'm new to node.js. I'm trying to build a GET Method which is calling an external API. The response which is an octet-stream should be passed through as response. Unfortunately I get a file download but the files are not readable.
app.get('/askForFile/:id',(req, res) => {
requestOptions2.url = apiOptions.server + '/externalFileAPI/Download?id=' + req.params.id
request(requestOptions2, (err, response, body) => {
if (err) {
console.log(err);
} else if (response.statusCode === 200) {
res.header('content-type', response.headers['content-type'])
res.header('content-disposition', response.headers['content-disposition'])
res.header('content-length', response.headers['content-length'])
res.send(body)
} else {
console.log(response.statusCode);
}
});
})
I wasted lot of hours to solve this problem. Would be great if someone could help me. Thanks in advance.
Best regards Mini25
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
