I'm working on a codebase and I have to extend a controller to allow uploading of PDF files. I'm submitting the file through jquery/ajax with formData.
The Backend contains of a pretty large framework, which has its own type of request - So using something like formidable is out of the question for handling the file upload server side.
My Problem: The POST request arrives on the server and when I log the body parameter that contains the file I get the following:
file: [
37, 80, 68, 70, 45, 49, 46, 51, 10, 37, 255, 255,
255, 255, 10, 56, 32, 48, 32, 111, 98, 106, 10, 60,
60, 10, 47, 84, 121, 112, 101, 32, 47, 69, 120, 116,
71, 83, 116, 97, 116, 101, 10, 47, 67, 65, 32, 49,
10, 62, 62, 10, 101, 110, 100, 111, 98, 106, 10, 55,
32, 48, 32, 111, 98, 106, 10, 60, 60, 10, 47, 84,
121, 112, 101, 32, 47, 80, 97, 103, 101, 10, 47, 80,
97, 114, 101, 110, 116, 32, 49, 32, 48, 32, 82, 10,
47, 77, 101, 100,
... 23741 more items
]
Which, from my understanding is an Array Buffer of the uploaded file. Now I've read that I can just write this to the file system with the fs library like this:
fs.writeFile(filename, data);
Which does create the file on the server, however it is always a corrupted file and not an actual pdf.
What am I missing, I'm assuming it has something to do with the encoding of the formData that I'm not aware of?