react-native-image-crop-picker icon indicating copy to clipboard operation
react-native-image-crop-picker copied to clipboard

How can i get binary data of image?

Open acv-tuandv opened this issue 6 years ago • 7 comments

Version

Tell us which versions you are using:

  • react-native-image-crop-picker v0.21.3
  • react-native v0.57.4

Platform

Tell us to which platform this issue is related

  • iOS

Expected behaviour

How can i get binary data of image?

Attachments

// stacktrace or any other useful debug info

Love react-native-image-crop-picker? Please consider supporting our collective: 👉 https://opencollective.com/react-native-image-crop-picker/donate

acv-tuandv avatar Dec 17 '18 08:12 acv-tuandv

same issue

zhangjialegh avatar Dec 19 '18 06:12 zhangjialegh

If you need to convert image into raw image (binary) then you have to use the base64 data.

Humbl-e avatar Jan 17 '19 17:01 Humbl-e

set includeBase64:true, in openPicker, you will get binary data in response object.

ImagePicker.openPicker ({ includeBase64:true, // add this line }).then(response => {})

NeerajaaG avatar Aug 14 '19 06:08 NeerajaaG


        ImagePicker.openCamera({
            width: 300,
            height: 400,
            cropping: true,
            cropperCircleOverlay: true,
            includeBase64: true
        }).then((image) => {
            const image_bytes = Buffer.from(image.data, "base64");
            console.log(image_bytes);
        })

ReactNativ avatar Aug 12 '22 17:08 ReactNativ

My object array is giving base64:null

OBJECT- [{"assetId": null, "base64": null, "duration": null, "exif": null, "height": 521, "rotation": null, "type": "image", "uri": "file:///data/user/0/host.exp.exponent/cache/ExperienceData/%2540akshat27032002%252Fschooldashboard/ImagePicker/e1c5ab03-099d-42c5-bd81-02a1e51fa734.jpeg", "width": 694}]

akshatkumar27 avatar Aug 28 '23 13:08 akshatkumar27

@akshatkumar27 @ReactNativ @zhangjialegh @acv-tuandv @Humbl-e Have you found anything converting image to binary in react native, I've to send binary in S3 api in my app.

premj-ekah avatar Jan 04 '24 13:01 premj-ekah

The below code worked for presigned URL upload to S3 which required the file data as binary

// You might need to install base-64 for encoding and decoding
import { decode as atob } from 'base-64';

// Function to convert Base64 string to binary data
const base64ToBinary = (base64) => {
  const raw = atob(base64);
  const rawLength = raw.length;
  const array = new Uint8Array(new ArrayBuffer(rawLength));

  for(let i = 0; i < rawLength; i++) {
    array[i] = raw.charCodeAt(i);
  }
  return array;
};

// Example base64 string (replace this with your actual base64 image string)
const base64String = 'iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAEklEQVR4nGP8z4APMOGVHbHSAEEsAROxCnMTAAAAAElFTkSuQmCC';

const binaryData = base64ToBinary(base64String);

Pass binaryData in request body

evojewel avatar May 10 '24 08:05 evojewel