How to convert PDF to base64 in react-native-document-picker?

Viewed 4281

I would like to convert the response of react-native-document-picker to base64 format. As a response I get the Uri of the file but unfortunately no base64.

this is my code:

const openDocumentFile = async () =>{
        try {
            const results = await DocumentPicker.pickMultiple({
              type: [DocumentPicker.types.pdf],
              readContent: true
            });
            for (const res of [results]) {
           
              console.log(res)
          
            };
                
          } catch (err) {
            if (DocumentPicker.isCancel(err)) {
            } else {
              throw err;
            }
          }
    } ```


1 Answers

you can use one this libs

react-native-image-base64 or rn-fetch-blob

import RNFetchBlob from 'rn-fetch-blob';

 RNFetchBlob.fs
  .readFile(filePath, 'base64')
  .then((data) => {
    setdata(data);
  })
  .catch((err) => {});
Related