Created
May 28, 2018 00:36
-
-
Save badcommandorfilename/2b35654d4e9af9117df08065e837fd89 to your computer and use it in GitHub Desktop.
Convert an ASP.NET Core image to a b64 data URL string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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