title: How to convert Base64 File to the actual file / original file in javascript and download it to client
body: <p>Im sorry if my question is a bit confusing but I think can clarify this by my detailed explanation.</p>
  
  <p>Im very new to saving/uploading files. I have recently been able to upload image and save it to database as <code>base64</code> (datatype = <code>mediumblob</code>) and display it again in the browser by setting <code>&lt;img src='base64_data_from_db' /&gt;</code>. </p>
  
  <p>Now for my actual problem.</p>
  
  <p>I have to upload file of any type to the database. After saving it, the user must be able to download the file using the browser by clicking a link/button (I used link). Im able to save the file using base64.</p>
  
  <p>The problem I have right now is that how can I convert the base64 string to the actual/original file (like MS Word, text file, image.. etc) and download it to the user. </p>
  
  <p>I removed the prefix of the base64 string and used <code>window.atob(str)</code> to 
  convert it. I can see somehow the contents of the file when I <code>console.log(window.atob(str))</code> but I don't know how to download it.</p>
  
  <p>NOTE: I used base64 when saving because I save it using JSON.
  Im using Java Spring Hibernate.
  I tried to google but most of the time I see <code>how to convert Base64 to image</code>... As I have said earlier I have already displayed the image in <code>&lt;img src=''/&gt;</code>. Im also reading about javascript FileReader but it requires a Blob as parameter and what I have is a base64 string.</p>
  
  <p>I have a very incomplete code below because I don't know what to do next...</p>
  
  <pre><code>// strBase64 -- The base64 string equivalent of the file 
  function convBase64ToFile(strBase64) {
      var tmp = strBase64.split(","); // To remove the prefix
      var converted = window.atob(tmp[1]); //
      console.log(converted); // Displays the content of the actual file
  }
  </code></pre>
  
  <p>Please help....</p>