Skip to content

Write file doesn't save base64 string on IOS, how to fix it ? #869

@andriiradkevych

Description

@andriiradkevych
import RNFetchBlob from 'rn-fetch-blob';
import {Platform} from 'react-native';

import {generateUuid} from './helpers';

export const saveImageBase64 = async (
  base64String: string,
  successCallback: () => void,
) => {
  const fileName = `${generateUuid()}.png`;
  const dirs = RNFetchBlob.fs.dirs;

  const Base64Code = base64String.split('data:image/png;base64,');

  const filePath = `${
    Platform.OS === 'android' ? dirs.DownloadDir : dirs.DocumentDir
  }/${fileName}`;

  RNFetchBlob.fs
    .writeFile(filePath, Base64Code[1], 'base64')
    .then(() => {
      if (Platform.OS === 'ios') {
        RNFetchBlob.ios.openDocument(filePath);
      } else {
        successCallback();
      }
    })
};

What I have here is saveImageBase64 function , that perfectly works on Android , it saves my image , and I'm happy , but on ios , function doesn't send any error , seems like all is working well , but when I try to open this image by RNFetchBlob.ios.openDocument(filePath); , it just show me :

2024-05-05 17 24 23

what does it mean ? and could someone show me how can I save my file , and open it , or just save on ios , because I don't see that anything saved to my Document dir

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions