An interesting feature of the application is the ability to download files in various formats such as xlsx, csv, and dat. To implement this, I have utilized a library called fileSaver.js.
While everything works smoothly for the dat/csv format, there seems to be an issue with the xlsx files being corrupted.
To troubleshoot this problem, I experimented with different conversion formats including:
utf8
base64
binary
Here's a snippet of how I implemented this:
// /* SERVER */ //
// Read data from file
fs.readFile(filePath, (err, data) {...})
// The API responds with the important parts "filename" & "data"
{"status":"ok","context":"writing the intermediate file","target":"/temp/","fileName":"name.xlsx","data":{"type":"Buffer","data":[72,82,65,67,67,69,83,83,32,10]}}
// /* CLIENT */ //
let json = JSON.stringify(data)
let buffer = Buffer.from(JSON.parse(json).data)
let read = buffer.toString('utf8')
let blob = new Blob([read])
FileSaver.saveAs(blob, fileName)