29 lines
854 B
C#
29 lines
854 B
C#
using Microsoft.AspNetCore.Http;
|
|
|
|
namespace InterfaceForward.Application.Helpers;
|
|
|
|
public static class CommonExtensions
|
|
{
|
|
public static async Task<byte[]> GetAllBytesAsync(this IFormFile file)
|
|
{
|
|
using (var stream = file.OpenReadStream())
|
|
{
|
|
return await stream.GetAllBytesAsync();
|
|
}
|
|
}
|
|
|
|
public static async Task<byte[]> GetAllBytesAsync(
|
|
this Stream stream,
|
|
CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
byte[] array;
|
|
using (MemoryStream memoryStream = new MemoryStream())
|
|
{
|
|
if (stream.CanSeek)
|
|
stream.Position = 0L;
|
|
await stream.CopyToAsync((Stream) memoryStream, cancellationToken).ConfigureAwait(false);
|
|
array = memoryStream.ToArray();
|
|
}
|
|
return array;
|
|
}
|
|
} |