如何在 react-native-document-picker 中将 PDF 转换为 base64?

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

我想将 react-native-document-picker 的响应转换为 base64 格式。作为回应,我得到了文件的 URI,但不幸的是没有 base64。

这是我的代码:

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;
            }
          }
    } ```


你可以使用一个这个库

react-native-image-base64 要么 rn-fetch-blob

import RNFetchBlob from 'rn-fetch-blob';

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