Skip to content

Instantly share code, notes, and snippets.

@badcommandorfilename
Created May 28, 2018 00:36
Show Gist options
  • Save badcommandorfilename/2b35654d4e9af9117df08065e837fd89 to your computer and use it in GitHub Desktop.
Save badcommandorfilename/2b35654d4e9af9117df08065e837fd89 to your computer and use it in GitHub Desktop.
Convert an ASP.NET Core image to a b64 data URL string
protected string Base64ImgString(string filepath) {
var serverpath = Path.Combine(HostingEnvironment.WebRootPath, filepath);
var contents = System.IO.File.ReadAllBytes(serverpath);
return $"data:image/png;base64,{Convert.ToBase64String(contents)}";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment