我从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)
- >
和回复标题 - >
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