I have to call a c# api which expects a byte array as one of the property in json.
public byte[] payload { get; set; }
public int id { get; set; }
public string file_type { get; set; }
In postman, I am making this call and able to push my file. But I am not able to convert the file into byte array in Node Js. In c# this is how it is converted :
byte[] bytes = System.IO.File.ReadAllBytes(@"C:\images\sample.jpg");
In node js I am trying this approach :
fs.readFile('sample.jpg', 'utf8', function(err, data){
// Display the file content
//console.log(data);
var convertedBuffer = Buffer.from(data, "utf-8");
var byteArray = convertedBuffer.alloc(8);
console.log(byteArray);
});
I am getting an error convertedBuffer.alloc is not a function. What is the wrong in this code please?