We're doing an integration between SAP BTP Document Management Service with a nest.js service to send and download files from repositories.
When I try to download any file, I got an encoding problem in the written file, no matter which encoding I chose (from null to forcing anything else on fs.writeFileSync() ).
Look at the example below, from a PNG image downloaded from BTP DMS:
Good file, downloaded from Postman:
Bad file, downloaded from Node:
Below is the code. We get a file list from a specific folder and download them:
const filesAsBinary = []
for await (const obj of objects) {
const response = await firstValueFrom(
this.http.get(sURL + `/${obj}`, {
headers: {
Authorization: `Bearer ${sJWTTOken}`,
'Accept-Encoding': 'gzip, deflate, br',
responseType: 'arraybuffer',
},
}),
)
filesAsBinary.push({ filename: obj, content: response })
and here, the file writing method:
for (const file of allFilesAsBinaryFromFolder) {
fs.writeFileSync(
`src/new-accession/documents/email-${folderName}/${file?.filename}`,
file?.content.data,
)
}
Any idea in how to properly write those files?
Thanks in advance!
I've tried at least 3 variations of this code - async and sync calls, the result is the same - to conclude the issue is in file writing, not the request itself.