title: Download base64 encoded file
body: <p>In React, I uploaded a file using:</p>
  <pre><code>        let reader = new FileReader();
          reader.readAsDataURL(file); 
          reader.onloadend = function() {
              let base64data = reader.result;    
              uploadFile(base64data);
              return;
          }
  </code></pre>
  <p>This gives me a Base64 encoded text <em>data:application/octet-stream;base64,JVBERi0xLj...</em>
  This is fine as when I decode 'JVBERi0xLj...' I get the correct text in case of a text file.</p>
  <p>When a download request is made to the server I get the same data back but I'm having a difficulty downloading the file. I receive the same base64 encoded string in the response from the server but unable to open the downloaded file.</p>
  <p>I have done the following:</p>
  <pre><code>                const blob = new Blob([fetchData], { type: 'application/pdf' })
                  let url = window.URL.createObjectURL(blob);
                  let a = document.createElement('a');
                  a.href = blob;
                  a.download = 'doc.pdf';
                  a.click();
  </code></pre>
  <p>Any ideas?</p>
  <p>Note: The upload file is converted to base64 to avoid any http communication issues.</p>
  <p>Solution following your suggestions:</p>
  <pre><code>                let fetchDataModified = `data:application/pdf;base64,${fetchData }`;
                  let a = document.createElement(&quot;a&quot;);
                  a.href = fetchData;
                  a.download = 'doc.pdf';
                  a.click();
  </code></pre>
  <p>When converting to Base64 during upload the data type was set to 'application/octet-stream'. However, when downloading I changed that to 'application/pdf' following Vaibhav's suggestion and used createElement instead of createObjectURL and it worked. Thank you</p>