How to convert base64 to bytes in Expo React Native?
Asked Answered
B

1

7

I'm trying to send image from image-picker to the server, but image-picker returns only base64.

How can I convert base64 to bytes in React-Native using expo?

Bisulcate answered 26/4, 2020 at 0:22 Comment(0)
B
14

So the solution for me was 'Buffer'.

It can be imported as:

import { Buffer } from "buffer";

Then all you need to do is:

let your_bytes = Buffer.from(your_base64, "base64");
Bisulcate answered 26/4, 2020 at 0:22 Comment(1)
expo-image-picker alternatively returns the path to the file on disk which you can pass in to fetch as formdata as in this example github.com/expo/examples/blob/…Slavish

© 2022 - 2024 — McMap. All rights reserved.