5

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?

Jake_3H
  • 372
  • 4
  • 14

1 Answers1

11

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");
Jake_3H
  • 372
  • 4
  • 14
  • 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 https://github.com/expo/examples/blob/628f8c61206ca422e156632aecfdfdf9e64f4e5c/with-formdata-image-upload/app/App.js#L180-L212 – brentvatne Apr 26 '20 at 00:38