【发布时间】:2021-02-27 08:25:56
【问题描述】:
我正在以二进制形式接收 response.data 在记事本中打开时,我可以保存一个文件 test.jpg,它是这样的二进制文本:
���� JFIF H H ��*Exif MM * b j( 1 r2 ��i � � �� ' �� 'Adobe Photoshop CS4 Windows 2009:01:31 22:25:45 ��� � @� > &( . � HH ���� JFIF HH �� Adobe_CM ��!1AQa"q�2���B# $R�b34r��C%�S���cs5���&D�TdE£t6�U�e���u��F'����������������Vfv ��������7GWgw�������� 5 !1AQaq"2����B#�R��3$b�r��CScs4�%��&5��D�T �dEU6te����u��F����������A�̰Y�u��7��l8��Z��~e����eXj�Γ����e ��fSˁ�'E���q��X%h�����������2v�8#������llx;����h $���
var img = response.data;
var path = "D:/Picture";
var filename = "test.jpg";
var buf = Buffer.from(img, 'binary');
fs.writeFileSync(path + "/" + filename, buf, function(error) {
if (error) {
console.error("write error: " + error.message);
} else {
console.log("Successful Write to " + path);
}
});
无法作为图片打开 我怎么了?
【问题讨论】:
-
为什么你需要二进制,你能不能只使用简单的base64图像编码?
-
实际上,来自 api api-data.line.me/v2/bot/message{messageId}/content 行的 response.data 二进制文件我该怎么办?