I am using fs for writing a pdf file to disk, the pdf file contains 7 pages which have contents, however when the file is getting written it doesn't have any content in it. The whole file is blank. Below is the code I am using for this
request.get({
url: spConfig.host + spConfig.sitecollection + '_api/web/GetFileByServerRelativeUrl(\'/sites/MSDS/Construction/ProductLabels/SD32382_-_ADVA Cast 596_(B2).pdf\')/$value',
headers: headers,
json: true
}).then(response => {
console.log('Inside Success')
// console.log(response)
// let writeStream = fs.createWriteStream(__dirname+'/wsdl/attachment.pdf')
console.log(response.length)
try {
fs.writeFileSync(__dirname+'/wsdl/attachment.pdf', response,'binary')
console.log('File has been written successfully')
} catch (err) {
console.log('Error in writing file')
console.log(err)
}
}).catch(err => {
spResponseCount = spResponseCount + 1
reject(err)
})