0

I'm using react-native-mail in my React Native app. This is my code:

const path = RNFetchBlob.fs.dirs.CacheDir + '/' + SHA1(this.fileSource.uri) + '.pdf'
const self = this;
let data = this.fileSource.uri.replace(/data:application\/pdf;base64\,/i, '');

RNFetchBlob.fs
    .writeFile(path, data, 'base64')
        .then(() => {
            Mailer.mail({
                subject: "Subject",
                body: "",
                recipients: [this.props.emailAddress],
                attachment: {
                    path: path,
                    type: 'pdf',
                    name: `attachment.pdf`,
                }
                }, (error) => {
                    ...
                });
        })
        .catch(() => {
            ...
        })

The value of path is "/data/user/0/com.<my-app-name>/cache/5cae2ea1e235873729dd158e19f3d122a1b46c73.pdf"

The value of data is TIAoxIDAgb2JqIAo8PCAKL1R5cGUgL0NhdGFsb2cgCi9QYWdlcyAyIDAgUiAKL1BhZ2VNb... (very long)

The mail() method throws the error Failed to find configured root that contains /data/user/0/com.<my-app-name>/cache/5cae2ea1e235873729dd158e19f3d122a1b46c73.pdf

Android version: 11
react-native: 0.63.4
rn-fetch-blob: 0.12.0
react-native-mail: git+https://github.com/marcinolek/react-native-mail.git

Does anyone know how I can approach this?

gkeenley
  • 6,088
  • 8
  • 54
  • 129

1 Answers1

0

Try changing the file location on an external path.

Kartik Rana
  • 160
  • 7