close

How to display binary data as image in React ?

Hello Guys, How are you all? Hope You all Are Fine. Today we are going to learn How to display binary data as image in React ? in javascript. So Here I am Explain to you all the possible methods here.

Without wasting your time, Let’s start This Article.

How to display binary data as image in React ?

  1. How to display binary data as image in React ?

    to display binary data as image in React You can simply concatenate your variable with server path:
    <img src={`http://yourip${cat.path}`} width="100px" height="100px" /> <img src={`${serverUrl}${cat.path}`} width="100px" height="100px" />
    This is working very well for me, hope this will help you!

  2. How to display binary data as image in React ?

    to display binary data as image in React You can simply concatenate your variable with server path:
    <img src={`http://yourip${cat.path}`} width="100px" height="100px" /> <img src={`${serverUrl}${cat.path}`} width="100px" height="100px" />
    This is working very well for me, hope this will help you!

Method 1


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 <img src={URL.createObjectURL(responseData)} />

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

Method 2

You can simply concatenate your variable with server path:

<img src={`http://yourip${cat.path}`} width="100px" height="100px" />

<img src={`${serverUrl}${cat.path}`} width="100px" height="100px" />

This is working very well for me, hope this will help you!

Summery

It’s all About this article. Hope all method helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you? Thank You.

Leave a Comment