2

I'm calling a third party API that generates an Avatar like this:

https.get(url, (response) => {
        var buffer = "";
        response.on('data', (data) => {
            logger.debug(JSON.stringify(data));
            buffer += data;
        });
         
        response.on('end', () => {
            logger.debug(buffer.toString('base64'));
            res.status(200).json({src:buffer});
        });
        
        response.on('error', (error) => {
            console.log(chalk.red.bgWhite('error' + error));
        });
    })

from the log it seems response.on('data', (data) => { is being called several times each time data is a different array of numbers which I don't know how to convert into an image I've tried prefix the data with data:image/png;base64, it didn't work. **when copy paste the url in the browser the avatar image (png) is shown [![enter image description here][1]][1]

these are the arrays of bytes in response.on('data', (data) =>{... getting in response

{"type":"Buffer","data":[137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,0,40,0,0,0,40,8,2,0,0,0,3,156,47,58,0,0,13,127,73,68,65,84,120,156,117,88,75,143,35,215,117,62,247,85,85,100,85,177,88,69,178,155,77,246,115,30,221,211,51,154,135,156,201,96,12,43,26,9,50,236,69,226,24,8,18,239,13,36,72,182,1,2,36,217,24,200,42,191,33,27,3,241,214,136,148,4,200,38,146,99,193,145,133,81,102,164,233,121,118,207,171,123,154,108,118,147,108,178,248,170,119,213,189,55,139,106,141,58,35,167,86,119,115,238,119,206,119,94,223,45,116,118,101,21,0,16,66,66,136,52,77,41,165,130,115,132,49,165,84,74,9,0,82,202,183,174,94,41,20,139,135,157,142,235,186,81,16,102,73,74,25,21,66,0,66,148,49,199,113,84,77,69,8,101,89,22,6,225,100,60,206,178,140,98,140,48,22,66,100,89,214,88,108,114,206,221,193,16,0,16,2,41,1,0,104,142,154,101,153,166,169,155,151,46,57,21,199,247,253,189,23,47,221,161,203,20,37,142,162,229,181,149,155,223,189,121,247,238,151,166,105,110,92,184,48,28,14,15,59,157,126,183,167,155,102,181,86,45,149,74,156,243,56,142,45,203,42,22,139,148,177,217,116,218,106,183,221,227,65,150,166,152,144,239,255,240,7,89,150,29,117,187,190,231,135,65,32,5,194,4,33,4,20,0,56,231,186,110,188,253,157,27,118,213,116,156,10,198,120,101,117,237,206,23,183,143,14,15,152,134,13,211,104,183,15,60,207,51,12,195,178,172,229,229,101,187,92,166,140,217,229,242,220,220,28,33,164,215,239,147,44,179,109,187,84,42,205,215,235,148,82,243,209,163,227,227,254,65,251,224,189,247]}
{"type":"Buffer","data":[222,59,123,238,220,135,31,126,184,186,182,234,79,125,14,254,143,254,190,249,235,127,26,12,246,18,156,135,219,92,90,92,255,209,76,212,95,200,140,170,154,82,50,75,215,174,95,125,251,143,170,171,215,245,48,140,218,173,182,239,251,138,162,104,154,150,36,73,150,101,122,177,88,95,88,40,219,118,20,69,134,174,75,41,9,33,211,233,116,111,111,47,138,34,130,177,170,168,235,235,235,37,203,250,242,238,93,0,160,132,216,182,131,21,88,186,82,80,13,44,133,164,8,131,76,168,126,190,91,92,96,229,237,107,137,152,37,99,84,46,57,116,170,106,170,42,184,87,212,12,85,83,21,198,48,198,71,71,71,135,135,135,24,99,93,215,9,198,23,55,55,159,98,60,153,78,103,158,231,186,174,162,40,161,235,38,73,18,71,145,231,121,154,166,237,108,111,11,41,29,199,25,186,110,24,69,4,211,56,224,82,0,0,96,0,64,24,69,65,50,189,183,92,36,21,66,200,171,253,221,169,231,34,12,156,103,133,18,57,187,190,102,151,237,28,117,56,28,34,132,0,192,48,140,48,12,251,253,254,91,111,189,5,0,5,77,27,141,70,179,217,140,16,34,56,143,162,136,82,26,199,113,154,166,245,249,249,27,55,110,172,172,172,48,69,97,170,2,32,1,0,0,176,20,64,85,209,185,75,227,190,181,127,248,92,47,152,181,90,117,183,245,44,20,3,197,228,106,129,248,190,151,102,169,4,112,93,247,217,179,103,227,241,120,99,99,35,138,99,166,40,123,123,123,183,111,223,70,0,65,16,40,138,82,178,172,203,151,47,191,123,235,214,213,107,215,44,203,74,211,52,138,162,48,12,59,7,7,179,233,172,226,56,138,170,2,146,132,32,144,64,1,161,140,243,230,226,146,105,152,59,79,118,146,56,62,123,254,44,70,108,183,253,104,252,124,58,233,162,186,221,43,232,170,235,186,213,74,101,161,209,232,116,58,24,33,85,85,15,218,109,203,178,178,44,195,132,4,65,96,154,38,163,84,72,185,191,191,31,134,97,81,215,147,52,149,0,199,131,193,81,183,11,8,144,36,2,178,216,147,193,152,99,138,40,72,137,16,170,205,213,52,77,187,114,245,202,206,206,206,97,231,200,208,141,23,247,15,189,105,66,21,84,160,163,241,20,40,33,142,227,212,235,245,87,175,94,61,126,252,184,94,175,151,203,229,70,163,145,166,105,183,219,197,24,251,65,128,9,9,182,183,131,32,40,22,139,211,233,84,211,180,249,249,249,205,205,205,131,131,131,157,167,219,105,136,137,138,63,251,197,224,120,47,81,13,68,133,16,170,170,58,78,229,233,206,211,106,173,250,246,219,111,199,73,188,243,100,123,230,77,168,74,9,163,197,162,30,69,145,239,121,47,119,119,251,253,126,183,219,45,151,203,92,8,219,182,11,133,66,154,101,113,146,140,39,147,52,77,61,207,139,227,24,99,12,18,152,194,24,99,195,225,112,103,103,199,15,124,224,216,92,136,17,53,188,163,136,176,16,36,80,33,132,89,50,21,85,57,56,104,247,122,189,70,179,209,104,52,14,90,237,107,87,222,50,75,230,253,7,143,211,52,93,93,93,77,146,228,209,163,71,245,122,253,226,197,139,148,82,4,136,16,210,106,183,57,231,142,227,204,205,205,97,140,41,165,170,170,154,166,217,239,247,41,161,205,197,102,28,199,66,8,66,176,76,105,88,124,226,249,99,106,173,162,120,107,239,85,155,74,41,21,69,45,22,139,235,27,27,156,115,198,104,175,215,99,4,125,239,214,173,78,187,85,208,212,119,111,221,154,159,155,219,223,223,127,240,224,193,98,179,89,178,44,211,52,117,93,231,156,3,0,198,88,74,41,165,164,148,34,140,121,150,113,158,53,26,141,225,112,8,0,140,49,198,24,38,88,74,148,14,151,247,182,95,108,158,89,91,94,90,222,219,107,81,41,37,83,152,170,105,135,135,135,190,231,151,237,114,235,213,126,177,80,32,140,21,138,250,185,243,231,166,227,137,170,40,174,235,154,166,217,235,245,134,195,225,220,252,252,242,242,114,154,166,8,33,41,37,161,148,16,210,61,58,138,163,168,104,24,134,105,18,66,108,219,230,156,99,140,135,131,193,196,29,234,102,169,58,55,55,95,90,183,237,250,104,48,37,185,191,140,50,41,196,194,66,29,33,52,153,76,6,131,65,146,166,105,154,86,230,230,155,43,171,157,78,231,222,151,95,49,198,28,199,225,156,43,170,154,166,41,99,44,71,101,76,113,143,251,31,127,244,75,191,223,41,171,184,0,73,28,6,8,33,198,24,198,56,73,18,71,103,183,222,249,125,3,165,207,182,239,41,150,130,16,78,147,88,72,73,65,74,66,73,183,219,245,102,179,229,149,229,44,77,31,110,221,143,252,89,28,134,106,161,232,56,78,165,82,233,28,28,20,138,69,203,178,22,22,22,52,77,123,241,252,197,158,186,183,176,176,64,8,81,84,181,245,242,229,159,254,228,199,127,245,215,127,11,16,2,160,127,251,232,63,238,222,219,46,22,84,0,224,92,252,241,79,126,188,121,249,122,22,13,254,226,167,127,78,176,13,82,28,31,31,75,41,49,32,148,165,153,148,114,60,30,183,91,173,32,8,146,36,73,146,244,184,123,132,49,17,66,80,74,139,122,177,213,106,249,190,239,56,14,0,36,105,210,122,181,191,179,189,211,61,58,74,146,184,84,46,127,247,15,222,145,50,12,61,15,0,175,172,46,129,148,0,8,0,1,64,251,224,48,139,142,169,102,204,213,234,182,94,241,103,19,63,136,48,198,20,99,236,123,94,165,90,41,20,10,73,28,123,158,23,6,193,230,230,70,18,69,163,65,191,92,173,129,148,253,222,113,146,36,158,231,221,191,127,191,86,171,169,170,154,196,73,24,134,47,95,184,152,80,69,85,59,7,157,171,215,223,233,29,189,232,245,30,45,173,173,33,4,82,74,4,32,132,224,128,255,245,151,31,169,5,163,82,117,58,199,147,178,93,49,74,22]}
{"type":"Buffer","data":[231,45,140,49,14,130,32,10,163,48,12,219,237,182,235,186,82,202,56,138,23,150,150,221,126,111,54,30,35,140,195,40,172,86,171,134,97,196,113,108,24,134,227,56,101,187,44,132,96,138,226,121,30,97,202,224,120,32,37,246,253,224,103,127,243,119,81,224,235,186,126,34,19,40,25,141,38,118,185,140,49,148,109,75,8,97,148,74,8,36,33,4,99,140,211,52,13,131,96,105,105,233,202,213,171,133,66,17,0,29,30,30,205,102,179,149,243,27,82,10,33,100,146,36,165,82,105,113,113,49,8,130,52,77,107,181,218,226,226,98,181,90,17,66,140,92,87,72,24,14,92,132,146,243,27,231,126,246,143,255,224,56,22,33,152,115,238,121,158,16,98,119,119,255,226,181,171,127,248,39,127,54,157,142,181,66,33,8,2,195,208,191,17,2,81,20,101,60,211,52,77,81,24,66,16,197,241,211,39,79,74,150,101,57,85,0,153,175,38,215,117,49,198,81,20,205,102,51,85,85,207,175,175,151,203,54,23,220,48,205,206,209,241,97,235,101,209,48,174,94,255,189,47,239,62,8,195,56,47,236,167,79,159,150,203,246,207,127,241,47,37,163,232,206,184,85,118,0,96,54,157,102,25,167,8,33,41,68,16,4,32,65,74,137,49,70,0,18,0,97,60,236,117,125,223,159,91,104,56,182,179,117,127,43,77,211,188,125,93,215,181,44,75,74,105,59,118,222,84,184,50,247,243,127,254,80,211,180,32,12,179,140,171,170,130,16,5,128,90,173,166,235,186,239,7,25,23,70,169,130,48,154,141,220,131,118,135,82,74,1,64,72,233,251,126,190,38,41,101,128,16,70,232,213,126,123,101,101,69,81,148,40,12,231,235,243,218,83,205,48,12,93,215,215,214,214,178,44,203,178,44,167,42,151,108,140,49,41,101,24,69,132,16,198,168,16,50,95,1,205,102,83,2,240,44,67,0,82,114,224,232,225,214,253,153,231,49,198,112,174,35,189,217,12,16,146,82,42,10,195,24,99,140,195,48,188,125,251,139,208,247,20,198,24,99,239,191,255,254,210,226,34,231,220,182,237,74,165,146,36,73,174,65,115,93,144,159,49,198,121,239,18,74,59,237,214,189,187,119,254,251,147,143,91,187,187,82,74,9,82,114,50,116,247,199,178,37,57,6,4,56,55,152,140,39,89,154,2,128,170,105,140,49,33,4,99,116,52,153,254,250,191,62,125,250,248,145,224,89,201,178,26,205,102,175,215,219,221,221,157,205,102,154,166,193,255,255,97,140,179,48,220,123,248,192,29,14,117,195,192,4,99,76,131,224,184,19,60,68,138,64,128,0,228,9,176,231,121,81,24,1,128,166,105,69,93,23,66,72,9,140,210,153,231,255,246,243,219,91,119,238,12,142,14,43,21,167,92,46,31,30,30,122,158,39,165,204,99,253,246,135,0,82,41,139,89,242,83,75,217,60,119,118,174,185,72,16,236,239,188,26,155,95,153,103,226,44,64,128,114,233,35,37,198,56,12,130,233,116,130,16,82,84,197,42,91,66,136,156,64,66,136,144,242,193,163,237,95,125,242,171,39,91,91,181,138,51,26,141,130,32,80,53,13,99,130,16,250,54,188,4,32,0,196,174,60,52,156,197,245,141,81,191,123,239,238,255,124,252,159,159,76,195,49,197,84,126,173,185,78,4,125,94,171,139,75,75,148,208,90,109,238,229,243,23,39,183,72,137,0,24,163,67,119,244,155,207,62,175,85,43,152,177,201,100,114,254,204,153,48,240,178,140,99,66,8,33,175,225,165,148,132,96,158,196,154,105,78,87,207,61,188,127,191,181,223,26,77,39,97,36,8,178,94,163,158,0,231,6,131,227,99,46,4,2,168,47,212,53,77,203,178,236,244,117,249,139,166,215,31,80,70,13,211,124,184,117,207,52,205,185,90,213,180,43,134,101,41,138,2,0,25,231,163,126,175,221,106,141,70,35,223,243,39,147,105,148,36,8,97,69,165,24,103,167,81,33,151,183,0,64,8,233,247,250,97,16,0,128,237,56,213,90,141,103,252,52,141,121,221,50,70,65,74,111,58,125,254,114,15,17,210,88,89,173,206,207,171,138,114,18,4,33,118,181,86,40,20,94,237,183,123,199,131,148,11,198,24,165,36,87,10,111,22,224,235,92,78,70,163,238,81,23,33,164,170,234,210,202,242,27,14,190,134,199,24,39,73,122,238,236,153,230,242,10,166,236,255,92,41,165,162,106,235,23,47,157,59,179,134,16,194,24,253,14,200,175,99,57,137,24,33,196,57,223,219,125,153,207,132,229,149,21,195,48,242,243,41,27,4,0,73,146,20,10,218,250,165,75,249,134,192,24,195,235,171,17,18,130,83,69,41,89,165,111,59,157,191,19,165,56,193,198,223,100,145,177,131,86,123,48,24,0,128,109,219,43,107,171,252,84,154,17,66,130,115,158,241,179,231,207,125,240,195,31,120,51,207,182,237,19,229,117,42,35,156,243,169,59,200,215,195,27,192,89,34,41,67,76,69,34,131,147,1,114,18,59,198,65,16,60,221,222,201,193,54,46,92,208,138,133,220,62,231,67,85,213,107,215,191,83,169,214,230,231,231,171,213,234,104,52,194,4,195,215,195,11,33,52,155,205,198,227,145,59,24,118,123,253,211,76,8,46,53,131,220,251,247,233,206,167,222,123,127,89,117,22,89,22,201,111,128,165,148,140,177,23,207,158,117,187,93,132,80,109,110,238,194,230,102,154,166,24,99,206,185,170,169,27,23,47,158,57,123,142,16,50,24,12,154,139,77,211,52,121,198,147,36,73,211,52,247,27,99,156,101,153,101,219,156,115,132,208,105,38,48,5,223,205,250,47,19,167,201,140,42,17,233,41,224,220,56,142,227,59,95,124,145,102,25,66,232,210,229,203,139,203,75,113,28,75,41,111,220,188,105,152,198,100,50,62,115,246,236,108,54,75,146,164,88,44,230,221,159,171,73,223,243,251,253,126,177,168,15,134,46,193,24,222,24,44,18,48,69,84,65,89,42,223]}
{"type":"Buffer","data":[164,58,15,90,81,148,246,126,235,193,214,22,38,68,211,180,235,55,110,228,122,195,178,202,141,70,99,50,158,24,134,222,108,54,179,44,147,82,198,113,12,0,148,210,209,104,180,191,191,159,166,41,83,20,219,182,41,165,249,228,127,3,251,132,251,211,197,245,6,225,91,95,126,117,208,106,229,207,130,155,239,124,239,198,205,155,221,110,215,48,140,249,250,252,104,52,42,149,74,138,162,228,178,48,223,99,133,66,225,194,230,133,70,163,209,122,181,175,27,198,153,181,21,199,46,191,217,20,0,8,1,85,78,234,245,77,224,156,240,44,77,63,255,236,183,163,209,200,48,12,195,48,234,141,133,133,198,66,107,191,213,108,54,21,69,225,156,7,65,144,175,112,132,208,238,238,238,131,251,15,246,118,247,8,33,102,201,12,195,240,226,213,107,239,222,122,215,42,149,184,16,167,250,2,120,42,71,7,105,26,75,132,1,229,127,125,190,229,26,74,146,164,209,108,188,247,193,7,165,82,41,203,50,74,233,100,50,209,117,157,82,42,132,200,127,231,100,89,22,4,65,154,164,186,161,27,134,145,36,9,165,212,117,93,179,84,34,8,221,249,252,243,199,219,59,138,162,156,158,33,152,32,193,229,239,142,248,117,178,15,15,58,191,249,244,211,145,59,194,24,11,33,202,229,114,126,0,0,66,136,162,40,249,230,55,75,102,165,82,33,132,48,198,210,52,197,8,37,113,18,71,81,24,133,223,222,93,60,59,113,226,127,1,181,180,176,98,13,120,198,41,0,0,0,0,73,69,78,68,174,66,96,130]}

and then in response.on('end', () =>{ this is what buffer looks like:

    �PNG

   
IHDR   (   (   �/:  
IDATx�uXK�#�u>�UUdU�XE��M�s��3����`+    2�E��
$H�$��*�!�ֈ��&�c���Qf��yvϫ{�lv�l���wս7�j�:#�Vws�w�w^�-tve BB�4M)��s�1�TJ     Rʷ�^)�����QfIJB B�1�qTMEeY�d<β�b�0BdY�Xlr��� ) h��e�����.9����/ݡ�%��嵕�߽y�in\�0;�~���f�V-�J��8�-�*����t�j���A�������Y�u���A �! 8�n���v�t�
�xeu������
�h�<�3ò���e�\�������!���,�m�T*����R�ѣ���A����;{�܇~����O}����������\Z\��L�_Ȍ��R2K׮_}������0�ڭ�����h��$I�ez�X_X(�vE��K)   !��too/�"�������%����] ��ض�X�RP
,���L�~�[\`��k��%cT.9t�j�*�W�US�0�GGG���c]� �77�b<�Ng�纮�(��&IG��y���lo)��nE�8�R  ` @EA2��\$Bȫ�ݩ�"�g�9��f��u8"� �0�0���[o� M�F�ٌ"8���R�q�����7n���0Ea�   �@UѹK㾵�\/��Zu��,��j����f�p]�ٳg��xcc#�c�({{{�o�F A(�R��˗/�{���k�,�J�4��0;���8���� �@�����i�;Ov�8>{�,Fl��h�|:颺�+���Je���t:!UU�m˲�,ÄA`�&�TH����aQד4� ǃ�Q��$�ؓ��c�(H����4M�r�����a��Ѝ��iBT���(!�����W�^=~��^����F���i����A�     ��� (���TӴ�����̓�����i���?���x/Q
D���:N����j����o�I��d{�M�J  �ŢE��y/ww��~��-��\۶�B�eq��'�4M=ϋ�c��c��pgg�|��\�5����$P!�Y2U98h�z�F��h4Z�kW�2K����4]]]M��ѣG�z��ŋ�R��j�9�����a�)��������)���f�BB�LiX|��cj��xk�U�J)E-���s�h��c}�֭N�U��woݚ��������b�Y�,�4u]� �XJ)���"�y�q�5��p �1�&XJ����_l�Y[^Z��kQ)%S��i������r��~�P ������㉪(�뚦�����������r��!)%���=:���h�iBl��c������f�:77_Z���h0%���2)��B!4�L�A��i�V��+��N�ޗ_1���+���)c,GeLq���K��)�� I!��8IGg���}�϶�)��N�XHIAJBI���f���,Mnݏ�Y�j��8N�R��E˲4M{��Ş����@QT������������?���.T �\��O~�y�z
��N�
RK)1 ����r<�[� �$I���{�1BPJ�z��j���8 $i�z�����=:J��T.�ޑ2= ��.��  @��0���f���^�g?�0�c�{^�Z)
I{����FE�A�\�����q�$��ݿ�V�����I�/_��PEU;��������-��!RJ ��������Ru:Ǔ�]1J�-�1� 
�0����R�8����~o6#��(�V��a�ql��8e�,�`��ya��x %���g�wQ��~"(�&v��1�mKa�J$!c��4
�`ii��ի�B �f���R
!d�$�Riqq1�4Mk����b�ZB�\WH\����~����8!�s�y�bww�⵫�'6���B!�пQe<�4MQB���'OJ�e9U ��&�u1�Q�f3UUϯ���6�0����a�e�0�^��/�>�8/�O������/%��θUv `6�f�!)D AJ�1F  a<�u}ߟ[h8��u+MӼ}]׵,KJi;v�T�2���PӴ ������Z����F��0��܃v�RJ@H��~�&)e�F��~{eeEQ�(����S�0]���ֲ,˲,�*�l�1)eE�ƨ2_�fS�,C Rr�������1�p�#���R*
�c��0�}�����c�����"�ܶ�J��$I�As]��1�y�J;�ֽ�w����[��RJ    Rr2t�Dz%987��'Y���i�1!ct4����>}����Yɲ�f����ݝ�f�����a��0�{��u��cL��<D�@� �    ��yQ��iE]BH �ҙ�����[w��+�\.z�'��c��� R)�Y�SK�<wv��H���_�g�,@�r�#%�8��t�RT�*[B��@B������_}�'[[��3�� P5
c��6�  Į<4����Q�{���|���L�1�T~��N}^��KK��Zm���'�H� �Cw���>�U+���dr�̙0�cB!�ᥔ�`�ĚiNW�=����M'a$�^�� ���c.�/�5M˲��u����PF
�|�u�4͹Zմ+�e)� �~��j�F#��'�i�$aE�g�Q!�� @���a ��8�Z�g�4�y�2FAJo:}�r�XY��ϫ�r!v�V(^��{ǃ���$W
o��\NF��Q!���������'Iz����
���\)��j�/�;����ȯc9�!�9��}�τ��0��) I�
���K������SE)Y�o;���8���d���V{0 �m�+k��T�B�s����}��x3϶��u*#��;����Y")CLE"��r;�A<����6.\Њ��>�CU�k׿S�������h4����!4����;v{��L.5�����Χ�{YuY�o�����Ϟu�]�Pmn���f��cι��/�9{�2��M�4yƓ$I�4�c�e�eۜs��i&0���/�Ɍ*�)��8��;_|�fB���ˋ�KqK)oܼi��d2>s��l6K��X,�ݟ�I����~���.��,0ETAY*ߤ:ZQ��~���&DӴ�7n�zòʍFc2���l6�,�R�q ���h�����)S۶)����������[_~u�j�ς��|��͛�n�0����h4*�J���0�c�B���F��z��ƙ��.�� UN��M���,M?�췣��0�0ꍅ��Bk��l6E�A��p�������v�!f�����k��z�*����x*GiK��}��J���l����R)�2J�d2�u�R*���dYA������$   ��u]�T"������;����!� ����u�:���ӑ;�!��r~  B��(��7Kf�R!�0��4�%qGQ���]<;q����b
x�)    IEND�B`�

My end goal is to save the base64 string to my DB and then return it to the client to be assigned to <img src=/>

Please help [1]: https://i.stack.imgur.com/F64BA.png

Kukula Mula
  • 1,788
  • 4
  • 19
  • 38

1 Answers1

0

data is a buffer. so you shouldnt json stringify it. Just concat all to obtain an image in binary format. or pipe all to a file.

response.on('data', (data) => {
    // data is a buffer
});

here is a full exemple : Getting binary content in node.js with http.request

Raphael PICCOLO
  • 2,095
  • 1
  • 12
  • 18
  • I've updated the question with the result of concatenating the data and then converting it to `buffer.toString('base64')` it still doesn't work. any suggestions? – Kukula Mula Aug 23 '21 at 22:21
  • it's not because you call a variable a buffer that it is a buffer :) what you did is converting a binary buffer to a string (hence destroying chars) did you try my link ? – Raphael PICCOLO Aug 23 '21 at 22:34
  • the `buffer.toString('base64')` is from the link you've shared :) Is there a difference between concatenating with += than with Buffer.concat? – Kukula Mula Aug 23 '21 at 22:53
  • var data = []; ... data.push(chunk); ... var buffer = Buffer.concat(data); – Raphael PICCOLO Aug 23 '21 at 22:55
  • 1
    "Buffer" is a buffer. strings are strings. += works only on string – Raphael PICCOLO Aug 23 '21 at 22:57