react-native-blob-util icon indicating copy to clipboard operation
react-native-blob-util copied to clipboard

Write base64 to device storage

Open ftanzarella-eviivo opened this issue 2 years ago • 0 comments

  • react-native: 0.17.4
  • react-native-blob-util: 0.17.2

I have an image file as a base64 encoded string that I would like to save to the device. What would be the most direct way to store this image?

This is what I have at the moment but running it on Android gives me [TypeError: Network request failed] - on iOS it seems to create the file because when I run it again I'm told that the file already exist. I just don't see the file on the device at all.

    let uri = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYA==';

    let fs = ReactNativeBlobUtil.fs;
    let { dirs } = fs;
    let base64 = ReactNativeBlobUtil.base64;
    let path = await fs.createFile(
      dirs.PictureDir,
      base64.encode(uri),
      'base64'
    );
    console.log(path)

ftanzarella-eviivo avatar Mar 16 '23 16:03 ftanzarella-eviivo