|
1 | 1 | using System; |
| 2 | +using System.Collections.Generic; |
2 | 3 | using System.IO; |
| 4 | +using System.Linq; |
| 5 | +using System.Runtime.CompilerServices; |
3 | 6 | using System.Threading; |
4 | 7 | using System.Threading.Tasks; |
5 | 8 | using ManagedCode.Storage.AspNetExtensions.Options; |
6 | 9 | using ManagedCode.Storage.Core; |
| 10 | +using ManagedCode.Storage.Core.Helpers; |
7 | 11 | using ManagedCode.Storage.Core.Models; |
8 | 12 | using Microsoft.AspNetCore.Http; |
9 | 13 | using Microsoft.AspNetCore.Mvc; |
10 | | -using ManagedCode.Storage.AspNetExtensions.Helpers; |
11 | 14 |
|
12 | 15 | namespace ManagedCode.Storage.AspNetExtensions; |
13 | 16 |
|
14 | 17 | public static class StorageExtensions |
15 | 18 | { |
16 | 19 | private const int MinLengthForLargeFile = 256 * 1024; |
17 | 20 |
|
18 | | - public static async Task<string> UploadToStorageAsync(this IStorage storage, IFormFile formFile, UploadToStorageOptions? options = null, |
| 21 | + public static async Task<BlobMetadata> UploadToStorageAsync(this IStorage storage, IFormFile formFile, UploadToStorageOptions? options = null, |
19 | 22 | CancellationToken cancellationToken = default) |
20 | 23 | { |
21 | 24 | options ??= new UploadToStorageOptions(); |
@@ -43,7 +46,17 @@ public static async Task<string> UploadToStorageAsync(this IStorage storage, IFo |
43 | 46 | } |
44 | 47 | } |
45 | 48 |
|
46 | | - return blobMetadata.Name; |
| 49 | + return blobMetadata; |
| 50 | + } |
| 51 | + |
| 52 | + public static async IAsyncEnumerable<BlobMetadata> UploadToStorageAsync(this IStorage storage, IFormFileCollection formFiles, |
| 53 | + UploadToStorageOptions? options = null, |
| 54 | + [EnumeratorCancellation] CancellationToken cancellationToken = default) |
| 55 | + { |
| 56 | + foreach (var formFile in formFiles) |
| 57 | + { |
| 58 | + yield return await storage.UploadToStorageAsync(formFile, options, cancellationToken); |
| 59 | + } |
47 | 60 | } |
48 | 61 |
|
49 | 62 | public static async Task<FileResult> DownloadAsFileResult(this IStorage storage, string blobName, CancellationToken cancellationToken = default) |
|
0 commit comments