I'm currently working on an application that allows the user to upload a file which gets sent to a express server that then converts that file into a bytearray that I can then store somewhere else.
However, I need to be able to convert this bytearray back into a file and send it back to the user. This is my current code in the express API:
app.post("/upload", async (req, res) => {
const file = req.files.file;
const filePath = "divali";
file.mv(filePath, async (err) => {
const nfile = fs.readFileSync(filePath);
let fileData = nfile.toString("hex");
let result = [];
for (var i = 0; i < fileData.length; i += 2)
result.push("0x" + fileData[i] + "" + fileData[i + 1]);
console.log(result);
var pfile = new Blob([result], { type: "application/pdf" });
// var fileURL = URL.createObjectURL(pfile);
console.log(pfile);
pfile.lastModifiedDate = new Date();
pfile.name = "some-name";
console.log(pfile);
});
});