20 lines
656 B
C#

namespace EnotaryoPH.Web.Common.Extensions
{
public static class IFormFileExtensions
{
public static string ToBase64StringUrl(this IFormFile file) => $"data:image/jpg;base64,{file.ToBase64String()}";
public static string ToBase64String(this IFormFile file)
{
if (file == null || file.Length == 0)
{
throw new ArgumentNullException(nameof(file));
}
using var memoryStream = new MemoryStream();
file.CopyTo(memoryStream);
var fileBytes = memoryStream.ToArray();
return Convert.ToBase64String(fileBytes);
}
}
}