new IFormFileExtensions

This commit is contained in:
jojo aquino 2024-12-16 01:02:10 +00:00
parent c766f1d0e9
commit 5873dba675
2 changed files with 19 additions and 0 deletions

View File

@ -0,0 +1,18 @@
namespace EnotaryoPH.Web.Common.Extensions
{
public static class IFormFileExtensions
{
public static string ToBase64StringUrl(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 $"data:image/jpg;base64,{Convert.ToBase64String(fileBytes)}";
}
}
}

View File

@ -0,0 +1 @@
global using EnotaryoPH.Web.Common.Extensions;