Open acv-tuandv opened 5 years ago
same issue
If you need to convert image into raw image (binary) then you have to use the base64 data.
set includeBase64:true, in openPicker, you will get binary data in response object.
ImagePicker.openPicker ({ includeBase64:true, // add this line }).then(response => {})
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);
})
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 @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.
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
Version
Tell us which versions you are using:
Platform
Tell us to which platform this issue is related
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