i'm trying to download pdf files from an api using the requst js module. i've set up a test route on express that fetches the file and send it back to the user.
let url = 'http://www.workagreements.economy.gov.il/Agreements/' + String(agrNum) + '.pdf';
let options = {
url: url,
method: 'GET',
};
request(options, function(err, response, body) {
let buff = Buffer.from(body, 'utf8');
res.attachment(String(agrNum) + '.pdf');
res.status(200).send(buff)
});
the file recieved is in the wrong encoding, resulting in a blank pdf file (with the correct number of pages). it seems that the problem starts with the encoding of the output of the request module. i've tried variuos encoding options for the buffer, but it didn't solve the problem. any ideas?