How to save pdf to android file system and then view PDF - react-native
<p>I am using the <a href="https://github.com/johanneslumpe/react-native-fs" rel="noreferrer">react-native-fs</a> and I am trying to save a base64 of a pdf file to my android emulators file system.</p>

<p>I receive base64 encoded pdf from the server.<br>
I then decode the base64 string with the line:  </p>

<pre><code>var pdfBase64 = 'data:application/pdf;base64,'+base64Str;
</code></pre>

<p><strong>saveFile() function</strong> </p>

<pre><code>saveFile(filename, pdfBase64){

    // create a path you want to write to
    var path = RNFS.DocumentDirectoryPath + '/' + filename;

     // write the file
     RNFS.writeFile(path, base64Image, 'base64').then((success) =&gt; {
       console.log('FILE WRITTEN!');
     })
     .catch((err) =&gt; {
       console.log("SaveFile()", err.message);
     });
}
</code></pre>

<p><strong>Error</strong><br>
When I try saving the pdfBase64 the saveFile() function catches the following error:  </p>

<pre><code>bad base-64
</code></pre>

<p><strong>Question</strong><br>
Can anyone tell where or what I am doing wrong?
Thanks.</p>