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
1 Answer
Reset to default 5Buffers 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
版权声明:本文标题:javascript - What is file buffer in Node.js? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744302671a2599657.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论