I need to use javascript on my server application. I have a variable holding a path to a PDF.
Now I want to read that file as a byte array to send it to another server. In Java, I would do something like this:
String myPath = "\path\to\my.pdf";
try {
byte [] myFile = Files.readAllBytes(Paths.get(myPath));
//Own function
sendData(myFile);
} catch (IO Exception e) {
e.printStackTrace();
}
I don't know what the javascript equivalent would be to this. With the fs library I can only read a file as an object of type 'Buffer':
import fs from 'fs';
let myPath = '\path\to\my.pdf';
let myFileAsBuffer = fs.readFileSync(myPath, { flag: 'r' });
//Own function
sendData(myFileAsBuffer);
But I always get an error because the server expects a byte array and not a Buffer, which looks something like this:
<Buffer 25 50 44 46 2d 31 2e 35 0d 0a 25 b5 b5 b5 b5 0d 0a 31 20 30 20 6f 62 6a 0d 0a 3c 3c 2f 54 79 70 ...>