Skip to content Skip to sidebar Skip to footer

How Do I Convert Image Uri Into Byte Expo

I'm uploading image using expo-image-picker. but the issue is I want to send the image to the server through WebAPI in the form of Byte. So how can I convert the image URI into Byt

Solution 1:

You can do something like this:

import { Buffer } from"buffer";

_pickImage = async () => {
  try {
    let result = awaitImagePicker.launchImageLibraryAsync({
      base64: true,
      allowsEditing: true,
      aspect: [4, 3],
    });

    if (!result.cancelled) {
      let imageByte = newBuffer(result.base64, "base64");

      this.setState({ image: result.uri });
    }
  } catch (e) {
      console.log(e);
  }
};

NOTE: You will need buffer package.

Post a Comment for "How Do I Convert Image Uri Into Byte Expo"