mozmorris / react-webcam

Webcam component
https://codepen.io/mozmorris/pen/JLZdoP
MIT License
1.66k stars 282 forks source link

Unable to view image stored in s3 bucket captured through react-webcam #283

Closed rajathongal closed 3 years ago

rajathongal commented 3 years ago

Bug reports:

the data returned from react webcam is of object type but when stored in s3 bucket and retrieved it is not possible to view the image as it is not binary or base 64, please do guide

mozmorris commented 3 years ago

@rajathongal could you share some sample code how you're using the component?

The getScreenshot method returns a base64 string not an object.

rajathongal commented 3 years ago

@rajathongal could you share some sample code how you're using the component?

The getScreenshot method returns a base64 string not an object.

Thank you for the response, I have resolved the issue, regarding the return method when I consoled i got object. here is what I did to resolve

var imgaeString = JSON.stringify(imgSrc);
var buf = Buffer.from(imgSrc.replace(/^data:image\/\w+;base64,/, ""),'base64') 
body:  buf,
ContentType: imageString.split('"data:')[1].split(';')[0],
ContentEncoding: 'base64'

and now for showing the image

u8 - unint8Array

  const tobase64 = (u8) => {
    return btoa(String.fromCharCode.apply(null, u8));
  }

var base64Flag = `data:${img.ContentType};base64,`;

var imgConverted = tobase64(img.Body)
setImage(base64Flag + imgConverted);