-2

I have an API (with axios) returning me an PNG image in the following form:

�PNG IHDR��C�; IDATx����eu}�������{��iq6�D�� B3(2(�&1�s�/�$G~�'��=���ILrr3�x��� ��0"�� �26�XU{Z���{�������������^2�Ab�dYsn�N��r�4>m���bD$i8�ZXGR�d2�&�:�T�E�<��@eY�Z5m���p)�~�_�h2���$��d2��:�4��i����x<i�M^�� ����#�9G� @LA�� �����#�J D+�L0,<.���B���� ���)�3b���$ ��VB� ���" ��bE0#�3A��V3��@�$�s��� ���}��&@�Y�B�E��&��1�&��&���3�i�} etc etc......

I need to convert the image from the above format into a base64 string, which I will then use to display the image inside a html tag. I've tried many way but with no success. Thus here we are :)

Does someone know how this transformation can be done in nodejs or javascript?

Thank you

I expected a base64 string

  • 2
    `I've tried many way` there's really only one way. Does your client side receive an ArrayBuffer or Blob as the content type? – Jaromanda X Aug 13 '23 at 23:53
  • https://stackoverflow.com/questions/10982712/convert-binary-data-to-base64-with-javascript – deekep Aug 13 '23 at 23:54
  • 1
    Data URLs are inefficient. You should be using Object URLs. – gre_gor Aug 13 '23 at 23:58
  • And why not use the URL directly, if it returns valid PNG image? – gre_gor Aug 13 '23 at 23:59
  • I think returned data type is not base64, it is binary data. So you have to use buffer. https://stackoverflow.com/questions/38503181/how-to-display-a-jpg-image-from-a-node-js-buffer-uint8array – Dev Conductor Aug 14 '23 at 01:12

0 Answers0