I am trying to create files (pdf, images, videos) from binary string stored in SQLite DB. The DB was created using a legacy PHP application and the file columns were all generated by simply inserting the result of file_get_contents() to the db.
Now, I am trying to create the file from these string values:
fs.promises
.mkdir(path.dirname("tmp/" + file.file_path), {recursive: true})
.then(x => fs.promises.writeFile("tmp/" + file.file_path, file.file_chunk));
Where file_path is the full path of the file and file_chunk is the binary string (result of file_get_contents).
When I run the PHP code on the same DB values, file_put_contents() gives me a correct file, however, the output of the above code in Node.js produces blank pdf or corrupt image files.
Is there a way to write files in nodeJS using the result of PHP's file_get_contents()?