haibert
haibert

Reputation: 158

React Native Is there a way to convert a base64 BACK to a uri?

In my React Native app I need to convert some base64 images back to uri. Reason being that uris are temporary and can be deleted from the cache. There are a lot of ways of converting URIs to base64 but not vice versa. Does anyone know how to do this?

Upvotes: 0

Views: 3266

Answers (1)

Susanne
Susanne

Reputation: 56

You could use the buffer library to decode base64 encoded data in a react native app.

npm i buffer 

Once installed you can import the buffer library into your react native app

import { Buffer } from 'buffer';

and then decode base64 encoded data

Buffer.from(data, 'base64');

The line above returns the decoded data as bytes and

Buffer.from(data, 'base64').toString('ascii');

returns the decoded data as an ascii encoded string.

Upvotes: 3

Related Questions