Here you append the data: URL scheme prefix and the content type and fact it is encoded in base64 to the base64 data.

this.setState({base64File: "data:image/png;base64," + img});

(Assuming that https://localhost:44348/api/user/GetFirstImage returns base64 encoded data rather than the more typical binary data of an image. If it doesn't then you have an extra problem and you need to encode the image).


Then here:

<img src={{uri: `data:image/gif;base64,${this.state.base64File}`}} />

You append the data: URL scheme prefix and the content type and fact it is encoded in base64 to the URL.

So now you have the preamble applied to the data twice which is will break it.

You also can't seem to make up your mind if the image is a GIF or a JPEG. You need to set the correct content-type!

Also, you are trying to set the src attribute to an Object instead of a String. It will get converted to a string — "[object Object]" — which will break it in yet another way.


This seems to be a very complex approach to the problem though. Is there a reason you aren't serving up a traditional image (instead of base64 data) from https://localhost:44348/api/user/GetFirstImage and just setting the src to that URL itself:

this.setState({imageUrl: "https://localhost:44348/api/user/GetFirstImage"});
...
<img src={this.state.imageUrl} />
Answer from Quentin on Stack Overflow
🌐
GitHub
github.com › react › react-native › issues › 33506
Cannot display base64 image in react-native app · Issue #33506 · react/react-native
March 27, 2022 - Description After building for release in XCode, I am unable to display an Image with base64 string (jpg) as its uri. When I build in debug mode, there is no issue displaying the image - so it is isolated to release builds. Surprisingly,...
Author   react
🌐
GitHub
github.com › facebook › react-native › issues › 12120
<Image> components with a base64 URI sometimes do not initially render. · Issue #12120 · facebook/react-native
January 30, 2017 - It's not always the same images that do it. It's complete random. Sometimes they will all load. Sometimes random ones will stay blank. Sometimes they'll show up after scrolling around the page. Sometimes they won't. Just create a page with several images loading different base64 sources.
Author   facebook
🌐
Stack Overflow
stackoverflow.com › questions › 73672440 › base64-image-doesnt-display-in-reactjs
base64 image doesn't display in reactjs
I think it should be a base64 encoded string instead of a buffer following the structure: data:image/png;base64,<<the base64 string here>>.
🌐
GitHub
github.com › react-native-maps › react-native-maps › issues › 5826
Issue: Base64 Image Not Rendering Inside Custom Marker (React Native Maps) (related to #5707) · Issue #5826 · react-native-maps/react-native-maps
December 26, 2025 - The base64 image should render inside the custom Marker the same way a static local image or remote URL image renders. In other words, when using a valid base64 string as the image source, the Marker should display the image correctly on Android devices.
Author   react-native-maps
🌐
GitHub
github.com › react-native-image-picker › react-native-image-picker › issues › 2189
Some images do not return a base64[🐛] · Issue #2189 · react-native-image-picker/react-native-image-picker
August 9, 2023 - launch the cameraroll picker in iOS, and select the top left pink flowers option (other images work fine), and there is no base64 value returned.
Author   react-native-image-picker
Find elsewhere
🌐
GitHub
github.com › react-native-elements › react-native-elements › issues › 3043
Image component does not render base64 · Issue #3043 · react-native-elements/react-native-elements
May 19, 2021 - Explain what you did (Required) Use expo-camera takePictureAsync(options) to take image. I pass the base64: true property to options and successfully get a base64 string back Expected behavior (Req...
Author   react-native-elements
🌐
Stack Overflow
stackoverflow.com › questions › 72177052 › base64-images-sometimes-dont-load-in-react-native
base64 images sometimes don't load in react native
May 9, 2022 - sometimes it shows the default picture and the console shows an error message that says JSON Parse error: Expected '}' (this happens most of the time) ... Thank you for your response ! i've tried fixing things here and there from the link you sent, but it didn't work for me, i'm suspecting the issue might be from the emulator ... Try your code in expo snack. I tried running code in expo snack and it worked for me. You can verify it this way whether it is a problem with emulator or not
🌐
Stack Overflow
stackoverflow.com › questions › 71640974 › how-to-display-a-png-image-encoded-in-base64-format-in-react
node.js - How to display a png image encoded in base64 format in react - Stack Overflow
<img src = {`data:image/png;base64,${image}`}/> Instead of running though, the image is not displayed. In a similar way to if alt text was needed. Not sure what to do. Any help would be greatly appreciated! node.js · reactjs · express · png · Share · Improve this question · Follow · asked Mar 27, 2022 at 23:12 · Brian Mason · 14722 silver badges1313 bronze badges 2 · If you check the html, does it show the image tag with the src?
🌐
React Native
reactnative.dev › docs › images
Images · React Native
May 28, 2026 - uri: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADMAAAAzCAYAAAA6oTAqAAAAEXRFWHRTb2Z0d2FyZQBwbmdjcnVzaEB1SfMAAABQSURBVGje7dSxCQBACARB+2/ab8BEeQNhFi6WSYzYLYudDQYGBgYGBgYGBgYGBgYGBgZmcvDqYGBgmhivGQYGBgYGBgYGBgYGBgYGBgbmQw+P/eMrC5UTVAAAAABJRU5ErkJggg==', ... In some cases you might only want to display an image if it is already in the local cache, i.e. a low resolution placeholder until a higher resolution is available. In other cases you do not ...
🌐
Medium
medium.com › @blturner3527 › storing-images-in-your-database-with-base64-react-682f5f3921c2
Storing Images in Your Database with Base64 & React | by Bri Turner | Medium
April 16, 2020 - In this snippet we just make a fetch call to our database and patch the image to the user’s profile. Lastly we will grab the image tag where we want to display the user’s image and add to the source: “data:image/png;base64” + the base64 string that we just saved into our database.
🌐
GitHub
github.com › facebook › react-native › issues › 21890
Base64 encoded image not visible in IOS UI · Issue #21890 · facebook/react-native
October 22, 2018 - Base64 encoded image not visible in IOS UI ###The Issue is happening only in IOS. In Android it is working fine. The base64 image in fetched from server and pushed to redux store in some page namel...
Author   facebook
🌐
Stack Overflow
stackoverflow.com › questions › 64941554 › react-display-an-image-converted-to-base64
React: Display an image converted to base64
Update : since I couldn't solve my problem. I bypassed it by making the server base64 the image before sending it. It is not ideal, but it solved temporarly my problem
Top answer
1 of 2
2

I believe you are missing an equals sign at the end of your base64 URL.

data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/2wBDAQMDAwQDBAgEBAgQCwkLEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBD/wAARCABQAFADASIAAhEBAxEB/8QAGAABAQEBAQAAAAAAAAAAAAAAAgEAAwn/xAAtEAEAAgEEAQMCBgEFAAAAAAABAhEAAxIhMSJBUWETcSOBkaHB8UIyYrHR4f/EABcBAQEBAQAAAAAAAAAAAAAAAAABAgP/xAAWEQEBAQAAAAAAAAAAAAAAAAAAARH/2gAMAwEAAhEDEQA/APS3aymVIvvFHaRnxTdrglUXdfES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/yF7wRjv1N0NSYVSHvjnKypWxrtwNES/pjs9DqsG2VECbd31eUJMFnu+C6xQu4xjMjuu75wP/2Q==

2 of 2
1

The problems may be due to the context that your onSelectFile is called from. Currently, your defining onSelectFile as an arrow function. This in turn means that this.setState will be undefined when your FileReader loads the image data (and then attempts to update the state of the component).

Consider the following code that outlines a possible solution for your problem:

class App extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
        src:''
    }
  }

  // Define as class method rather than arrow function
  onSelectFile(e) {

    if (e.target.files && e.target.files.length > 0) {
      const reader = new FileReader();
      reader.addEventListener(
        "load",
        () =>
          this.setState({
            src: reader.result,
            openCropper: true
          }),
        false
      );
      reader.readAsDataURL(e.target.files[0]);
    }
  }

  render() {
    return (
      <div>
     {/* invoke onSelectFile in this way to ensure calling context is 
         current component */}
     <input type="file" onChange={(e) => this.onSelectFile(e)} />
     <img src={this.state.src} />
      </div>
    )
  }
}

ReactDOM.render(<App />, document.querySelector("#app"))

For a working demo, please see this jsFiddle - hope this helps!

🌐
Stack Overflow
stackoverflow.com › questions › 67455557 › base64-image-rendering
reactjs - Base64 Image Rendering - Stack Overflow
<Image resizeMode='contain' source={{ uri: 'image/jpg:base64,' + image }} style={{ width: '100%' }} />
🌐
Stack Overflow
stackoverflow.com › questions › 76637896 › base64-image-never-renders-in-react
reactjs - Base64 Image never Renders in React - Stack Overflow
July 7, 2023 - FileReader function gives me a base64 encoded image which i assign to the imgg variable and upon reRendering I am able to see that the backgroundImage property is set with the url() but the image nevers shows up on the browser . Would appreciate any help . Thanks! ... I think the src of the <img>-tag has to start (depending on the image format) with "data:image/jpeg;base64," for example. This is followed by the base64 string. But I'm not sure if this is the cause because I don't know the code of the FileReader function.
🌐
GitHub
github.com › facebook › react-native › issues › 16695
Scroll view is not showing base64 images · Issue #16695 · facebook/react-native
November 6, 2017 - On App.js create a function to drilll down the object and create an image array of the base64 images ... The expected behavior was for the images to be displayed in the scroll view as an image carousel allowing the user to scroll through all the images · The application does not display the images in the scrollview.
Author   facebook
🌐
GitHub
github.com › react-native-image-picker › react-native-image-picker › issues › 525
image is not converting to base64 · Issue #525 · react-native-image-picker/react-native-image-picker
March 25, 2017 - Here is the line of code i used for base64 conversion let source = { uri: 'data:image/jpeg;base64,' + response.data } But it not showing correct base64 image
Author   react-native-image-picker