Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetch error when convert base64 to blob on react-native

This error occurs when I run the following code in React Native to convert base64 to blob on Android

let url = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgA...';
let res = await fetch(url);
let blob = await res?.blob();

enter image description here

like image 781
Heisenberg Avatar asked Jun 08 '26 00:06

Heisenberg


1 Answers

If you want to convert Base64 to blob you can use the following way :

Install the package below

npm install buffer --save

First, convert your Base64 to the array of bytes

import { Buffer } from "buffer";


const base64 = 'iVBORw0KGgoAAAANSUhEU ....'
let your_bytes = Buffer.from(base64, "base64");

Then convert it to blob:

const blob = new Blob([your_bytes], { type: 'YOUR TYPE' })
like image 162
AbolfazlR Avatar answered Jun 10 '26 10:06

AbolfazlR



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!