How to display binary data as image in React?

前端 未结 3 511
自闭症患者
自闭症患者 2020-11-27 14:12

I am receiving a bindata from the Nodejs server and now from that I need to display an image.

How can I achieve this? Is there any method to convert bindata to JPEG

3条回答
  •  攒了一身酷
    2020-11-27 14:47

    If you need to display binary image from api, and the binary data look like this ����JFIF��� ��� convert to blob first and use URL.createObjectUrl(BLOB);

    1. using axios, add {responseType: 'blob'} to the config

    or

    1. using fetch api, response.blob();

    display image from blob

    I don't know is this the best solution or not, but it works.

提交回复
热议问题