I am working on functionality, where i needs to send array of buffer containing imageData In object along with some other fields,
SAMPLE INPUT :
payload = { input:'buffer', data:ARRAY_OF_BUFFER, output:'buffer' }
I tried using JSON.stringify(payload)
but it’s not working, might be the issue with buffer, i am not sure it’s converting back buffer properly or not.
Advertisement
Answer
A way to deal with this just pass payload as JSON.stringify(payload) what JSON.stringify is doing with buffer data is it’s converting buffer data like this
{ type: 'Buffer', data: [ 72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100 ] }
so you can convert back into in it’s original form by just doing this
Buffer.from(data);
you will get the original buffer back.