Matt
Matt

Reputation: 344

How to read and open a .pem file in React Native

Hey I'm trying to open the file explorer and choose only .pem files from the device, and then get the string of the .pem content.

Upvotes: 1

Views: 1312

Answers (1)

Matt
Matt

Reputation: 344

This is how to do it:


import { Platform } from 'react-native';
import DocumentPicker from 'react-native-document-picker';
import { FileSystem } from 'react-native-file-access';
...

const openFile = () => {
      const type = Platform.OS === 'ios'
        ? 'public.x509-certificate'
        : ['.pem', 'application/x-pem-file'];
      const res = await DocumentPicker.pickSingle({ type });

      const stringifyPEM = await FileSystem.readFile(res.uri);
    }

Upvotes: 1

Related Questions