mirror of
https://github.com/fergalmoran/podnoms.git
synced 2025-12-25 02:39:47 +00:00
24 lines
704 B
C#
24 lines
704 B
C#
using System.Threading.Tasks;
|
|
|
|
namespace PodNoms.Api.Utils
|
|
{
|
|
public class ImageUtils
|
|
{
|
|
public static async Task<string> GetRemoteImageAsBase64(string url)
|
|
{
|
|
|
|
var file = await HttpUtils.DownloadFile(url);
|
|
return await ImageAsBase64(file);
|
|
}
|
|
public static async Task<string> ImageAsBase64(string file)
|
|
{
|
|
if (System.IO.File.Exists(file))
|
|
{
|
|
byte[] data = await System.IO.File.ReadAllBytesAsync(file);
|
|
string base64 = System.Convert.ToBase64String(data);
|
|
return $"data:image/jpeg;base64,{base64}";
|
|
}
|
|
return string.Empty;
|
|
}
|
|
}
|
|
} |