admin管理员组

文章数量:1405392

I have seen in Multer (file uploading package for node.js) that I can store the file as usual and instead, I can have a buffer.

The buffer looks like this when console log:

<Buffer ff d8 ff e2 0b f8 49 43 43 5f 50 52 4f 46 49 4c 45 00 01 01 00 00 0b e8 00 00 00 00 02 00 00 00 6d 6e 74 72 52 47 42 20 58 59 5a 20 07 d9 00 03 00 1b ... >

What is this? How can it be used? Is this the image that was uploaded? If then - how to display this? Should it be saved in the DB and then.. what? Should I create a file from it and save the file and the actual reason for this is to not upload a real file until all validations are okay?

I have seen in Multer (file uploading package for node.js) that I can store the file as usual and instead, I can have a buffer.

The buffer looks like this when console log:

<Buffer ff d8 ff e2 0b f8 49 43 43 5f 50 52 4f 46 49 4c 45 00 01 01 00 00 0b e8 00 00 00 00 02 00 00 00 6d 6e 74 72 52 47 42 20 58 59 5a 20 07 d9 00 03 00 1b ... >

What is this? How can it be used? Is this the image that was uploaded? If then - how to display this? Should it be saved in the DB and then.. what? Should I create a file from it and save the file and the actual reason for this is to not upload a real file until all validations are okay?

Share Improve this question asked Jan 19, 2019 at 17:54 Raz BuchnikRaz Buchnik 8,42117 gold badges62 silver badges116 bronze badges 2
  • If a high-level overview helps... www.techopedia./definition/2759/buffer – Cat Commented Jan 19, 2019 at 17:57
  • Firstly, this is not image code, it's a file signature, not fully sure which kind yet. Also, how did you get that from a picture? – The Bomb Squad Commented Jan 19, 2019 at 18:08
Add a ment  | 

1 Answer 1

Reset to default 5

Buffers are just array of bytes (printed in hexadeciamal here 00 to ff, or 0 to 255.

You can represent any file as a byte array, actually fs.writeFile can takes a Buffer directly.

You can convert it to string.

Check it out on the official documentation https://nodejs/api/buffer.html#buffer

本文标签: javascriptWhat is file buffer in NodejsStack Overflow