将Base64 Buffer作为映像保存到磁盘

时间:2015-08-01 17:21:49

标签: javascript node.js socket.io

Node.js应用中,我通过Socket.io向服务器发送图片。在服务器中,我这样得到它,我想将它保存在磁盘上。它保存但我无法打开图像和图像查看器说它已损坏!文件大小是正确的但我无法打开它。在代码中有什么我想念的吗?

    socket.on('newImage', function (data) {
       var img = data.image;
       var coded_img = new Buffer(img, 'base64');

       fs.writeFile("out.png", coded_img,'base64', function(err) {
             if (err) throw err;
             console.log('File saved.')
       });
    });

1 个答案:

答案 0 :(得分:0)

我解决了它,使用此功能,我恢复了主要图像数据:

xxxxx@user:/tmp$ sudo -u postgres /usr/local/pgsql/bin/initdb -D 

/usr/local/pgsql/data/
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
creating template1 database in /usr/local/pgsql/data/base/1 ... FATAL:  access method "btree" does not support unique indexes
child process exited with exit code 1
initdb: removing contents of data directory "/usr/local/pgsql/data"