示例#1
0
        public async static Task <string> ConvertToBase64(string fileName)
        {
            if (!File.Exists(fileName))
            {
                return(string.Empty);
            }

            string format = "data:{0};base64,{1}";

            byte[] buffer = await FileHelpers.ReadAllBytesRetry(fileName);

            string extension   = Path.GetExtension(fileName).Substring(1);
            string contentType = GetMimeTypeFromFileExtension(extension);

            return(string.Format(CultureInfo.InvariantCulture, format, contentType, Convert.ToBase64String(buffer)));
        }