new method ex ToBase64String

This commit is contained in:
jojo aquino 2025-01-01 16:26:23 +00:00
parent 285ada3d13
commit ef349eceb1

View File

@ -2,7 +2,9 @@
{ {
public static class IFormFileExtensions public static class IFormFileExtensions
{ {
public static string ToBase64StringUrl(this IFormFile file) 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) if (file == null || file.Length == 0)
{ {
@ -12,7 +14,7 @@
using var memoryStream = new MemoryStream(); using var memoryStream = new MemoryStream();
file.CopyTo(memoryStream); file.CopyTo(memoryStream);
var fileBytes = memoryStream.ToArray(); var fileBytes = memoryStream.ToArray();
return $"data:image/jpg;base64,{Convert.ToBase64String(fileBytes)}"; return Convert.ToBase64String(fileBytes);
} }
} }
} }