title: Convert a file from to Base 64 using JavaScript and converting it back to file using C#
body: <p>I am trying to convert pdf and image files to base 64 using javascript and convert it back to file using C# in WEB API.</p>
  
  <p>Javascript</p>
  
  <pre><code>var filesSelected = document.getElementById("inputFileToLoad").files;
  if (filesSelected.length &gt; 0)
  {
      var fileToLoad = filesSelected[0];
      var fileReader = new FileReader();
      fileReader.onload = function(fileLoadedEvent) 
      {
          var textAreaFileContents = document.getElementById("textAreaFileContents");
          textAreaFileContents.innerHTML = fileLoadedEvent.target.result;
      };
      fileReader.readAsDataURL(fileToLoad);
  }
  </code></pre>
  
  <p>C#</p>
  
  <pre><code>Byte[] bytes = Convert.FromBase64String(dd[0].Image_base64Url);
  File.WriteAllBytes(actualSavePath,bytes);
  </code></pre>
  
  <p>But in API I'm getting exception as <code>{"The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters. "}</code></p>
  
  <p>Please tell me how to proceed with this...
  Thanks  </p>