I have an api that gives me raw png data as response, Want to convert the raw data to a file or a base64 string that can be invoked later. Below is the sample of the response that I get from the api. Can someone tell me on how this can be achieved
�PNG
IHDR���(-sRGB���sBIT|d� IDATx���w|SU��'I��i��[(��7(�NDQ� �*����EPq�" ���""�Be�e�M�i����(���mҦM�����y�7�{����{���'��"A(A �����������d��h�^k����"���m"""""""���D.�X�P$tt{�������.kB�BNk'""""""r,�@�9t"""""""'��NDDDDDD�Љ�������:�`@'""""""r�DDD���f܊뮽���ha��s1~�dG7����)�8�DDD���? ���ᗭ?5��g�8�X� ��'�ii)�hb�L�vn��.����4=/��zTV�c�>|����h�������g�8�1���Pb^{e9���p���N�GDDt1�:�YS&Omqn�k�������s�c��/���k>����V��՟���S'q㌙�w�C������,���!��v������ GЉ����T!6�'��c��� pqc��I�����������=��F��Z�F���X�~5�Z-�B#���k����@QQ!�{�-\;m&�����|�i~��W�\.ǃ�b��Q����X��*�T�����s;�����
You can use fs Module
let fs = require('fs')
let writer = fs.createWriteStream('xyz.png')
writer.write(<RAW data here>);
If you getting file directly in body then
let writer = fs.createWriteStream('xyz.png');
let fl = res.body.pipe(writer); (res is your response from api)
fl.on('finish', () => {...Things to do})