I am working on functionality, where i needs to send array of buffer containing imageData In object along with some other fields,
SAMPLE INPUT :
JavaScript
x
2
1
payload = { input:'buffer', data:ARRAY_OF_BUFFER, output:'buffer' }
2
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
JavaScript
1
5
1
{
2
type: 'Buffer',
3
data: [ 72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100 ]
4
}
5
so you can convert back into in it’s original form by just doing this
JavaScript
1
2
1
Buffer.from(data);
2
you will get the original buffer back.