Answer the question
In order to leave comments, you need to log in
Why is the buffer being transformed?
When uploading an image, I use Multer, which returns req.file
. Next, req.file
I need to transfer this to another function (or rather, to a process). But it changes from
buffer:
<Buffer 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 04 ef 00 00 03 ce 08 02 00 00 00 d8 d3 ab 62 00 00 00 03 73 42 49 54 08 08 08 db e1 4f e0 00 00 ... 764163 more bytes>
buffer:
{ type: 'Buffer',
data:
[ 137,
80,
78,
71,
13...
...
Answer the question
In order to leave comments, you need to log in
It's simple, paste into the console
console.log(`<Buffer ${(137).toString(16)} ${(80).toString(16)} ${(78).toString(16)}`)
let buffer = new Buffer.from("example");
console.log(buffer);
// <Buffer 65 78 61 6d 70 6c 65>
let json = buffer.toJSON();
console.log(json);
// {type: "Buffer", data: [ 101, 120, 97, 109, 112, 108, 101 ] }
let example = new Buffer.from(json);
console.log(example);
// <Buffer 65 78 61 6d 70 6c 65>
function printBuffer(buffer){
console.log(buffer);
}
printBuffer(example);
//<Buffer 65 78 61 6d 70 6c 65>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question