在 Expressjs 中,我上传图像。它以 7 位编码的缓冲区形式出现:
{ fieldname: 'file',
originalname: 'img.JPG',
encoding: '7bit',
mimetype: 'image/jpeg',
buffer: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 00 64 00 64 00 00 ff db 00 43 00 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 0
1 01 01 01 01 01 ... >,
size: 873066 }
如何将其作为图像保存到文件系统?某些内容已保存,但不是图像:
Windows Photo Viewer can't open this picture because the file appears to be damaged, corrupted of too large.
这些不起作用:
fs.writeFile('uploaded-img.jpg', req.file, 'ascii', function(err) {
fs.writeFile('uploaded-img.jpg', req.file.toString('ascii'), 'ascii', function(err) {
最佳答案
怎么样:
fs.writeFile('uploaded-img.jpg', req.file.buffer, 'ascii', function(err) {
关于node.js - 如何将图像写入具有缓冲区的服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33381009/