Is it possible to get the binary data from an image in React-Native?

前端 未结 2 796
独厮守ぢ
独厮守ぢ 2021-02-15 16:58

I\'m using react-native-camera and I\'m having trouble getting the image as binary data in react-native. I need this to be able to upload images to our

2条回答
  •  难免孤独
    2021-02-15 17:50

    An alternative if you're already using react-native-camera is upon capturing the image, you request it as base64 directly as such:

    takePicture = async function(camera) {
      const options = { quality: 0.5, base64: true, doNotSave: true }
      const data = await camera.takePictureAsync(options)
    
      console.log(data.base64)
    }
    

    If your goal is to only snap the picture, show a preview perhaps then upload to the server and move on, then the benefit of this approach is that it won't save that photo in your device cache (doNotSave: true). Which means that you don't need to worry about cleaning those up after you're done.

提交回复
热议问题