在节点js中获取原始图像

时间:2018-01-17 05:10:57

标签: node.js request buffer

我从api收到了原始图片,但是如何将原始图片上传到我的本地文件夹?这是我的代码,它只是上传原始图片但保存文件已损坏且无法打开

var path = "{HTTP://URL-TO-API/}";
request(path, function (errror, response, body) {
  var buffer = new Buffer(body, 'binary');
  fs.writeFile('out.png', buffer, function (error) {
    if (err) throw err;
  });
});

此处console.log(body) - >

shown raw image in terminal

和回复标题 - >

headers: { date: 'Wed, 17 Jan 2018 01:41:36 GMT',
 server: 'Apache/2.2.22 (Debian)',
 connection: 'close',
 'access-control-allow-origin': '*',
 'transfer-encoding': 'chunked',
 'content-type': 'image/png' }

node ver:8.9.2

0 个答案:

没有答案