From 84b7e85d488ef6b68a0ad8e6a559118da0e98ad7 Mon Sep 17 00:00:00 2001 From: zHaytam Date: Fri, 13 Mar 2020 15:16:27 +0100 Subject: [PATCH 1/2] Add GetAllBytesAsync to AbpFormFileExtensions This makes it easier to get an array of bytes directly from an `IFormFile` --- .../Microsoft/AspNetCore/Http/AbpFormFileExtensions.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/AspNetCore/Http/AbpFormFileExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/AspNetCore/Http/AbpFormFileExtensions.cs index c808250a3e..dfc4df0339 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/AspNetCore/Http/AbpFormFileExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/AspNetCore/Http/AbpFormFileExtensions.cs @@ -1,4 +1,5 @@ using System.IO; +using System.Threading.Tasks; namespace Microsoft.AspNetCore.Http { @@ -11,5 +12,11 @@ namespace Microsoft.AspNetCore.Http return stream.GetAllBytes(); } } + + public static async Task GetAllBytesAsync(this IFormFile file) + { + using var stream = file.OpenReadStream(); + return await stream.GetAllBytesAsync(); + } } } From 2c9798298a44a979172745bafed9b2145816bcb3 Mon Sep 17 00:00:00 2001 From: maliming Date: Sun, 15 Mar 2020 11:19:04 +0800 Subject: [PATCH 2/2] Update AbpFormFileExtensions.cs --- .../Microsoft/AspNetCore/Http/AbpFormFileExtensions.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/AspNetCore/Http/AbpFormFileExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/AspNetCore/Http/AbpFormFileExtensions.cs index dfc4df0339..31768b5e6a 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/AspNetCore/Http/AbpFormFileExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/AspNetCore/Http/AbpFormFileExtensions.cs @@ -15,8 +15,10 @@ namespace Microsoft.AspNetCore.Http public static async Task GetAllBytesAsync(this IFormFile file) { - using var stream = file.OpenReadStream(); - return await stream.GetAllBytesAsync(); + using (var stream = file.OpenReadStream()) + { + return await stream.GetAllBytesAsync(); + } } } }