Skip to content

Commit 97bd762

Browse files
Hurko-VolodymyrHurko Volodymyr
andauthored
Add methods from StorageFromFileExt and StorageExt (#46)
Co-authored-by: Hurko Volodymyr <hurko@managed-code.com>
1 parent a5dfa50 commit 97bd762

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

ManagedCode.Storage.AspNetExtensions/BaseController.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.Runtime.CompilerServices;
4+
using System.Threading;
25
using System.Threading.Tasks;
36
using ManagedCode.Communication;
47
using ManagedCode.Storage.Core;
58
using ManagedCode.Storage.Core.Models;
69
using Microsoft.AspNetCore.Components.Forms;
10+
using Microsoft.AspNetCore.Http;
711
using Microsoft.AspNetCore.Mvc;
812

913
namespace ManagedCode.Storage.AspNetExtensions;
@@ -28,4 +32,46 @@ protected async Task<Result<BlobMetadata>>UploadToStorageAsync(IBrowserFile form
2832
{
2933
return await _storage.UploadToStorageAsync(formFile, options);
3034
}
35+
36+
protected async Task<Result<FileResult>> DownloadAsFileResult(string blobName, CancellationToken cancellationToken = default)
37+
{
38+
return await _storage.DownloadAsFileResult(blobName, cancellationToken);
39+
}
40+
protected async Task<Result<FileResult>> DownloadAsFileResult(BlobMetadata blobMetadata, CancellationToken cancellationToken = default)
41+
{
42+
return await _storage.DownloadAsFileResult(blobMetadata, cancellationToken);
43+
}
44+
45+
protected async Task<Result<BlobMetadata>> UploadToStorageAsync(IFormFile formFile,
46+
UploadOptions? options = null,
47+
CancellationToken cancellationToken = default)
48+
{
49+
return await _storage.UploadToStorageAsync(formFile, options, cancellationToken);
50+
}
51+
52+
protected async Task<Result<BlobMetadata>> UploadToStorageAsync(IFormFile formFile,
53+
Action<UploadOptions> options,
54+
CancellationToken cancellationToken = default)
55+
{
56+
return await _storage.UploadToStorageAsync(formFile, options, cancellationToken);
57+
}
58+
protected async IAsyncEnumerable<Result<BlobMetadata>> UploadToStorageAsync(IFormFileCollection formFiles,
59+
UploadOptions? options = null,
60+
[EnumeratorCancellation] CancellationToken cancellationToken = default)
61+
{
62+
foreach (var formFile in formFiles)
63+
{
64+
yield return await _storage.UploadToStorageAsync(formFile, options, cancellationToken);
65+
}
66+
}
67+
protected async IAsyncEnumerable<Result<BlobMetadata>> UploadToStorageAsync(IFormFileCollection formFiles,
68+
Action<UploadOptions> options,
69+
[EnumeratorCancellation] CancellationToken cancellationToken = default)
70+
{
71+
foreach (var formFile in formFiles)
72+
{
73+
yield return await _storage.UploadToStorageAsync(formFile, options, cancellationToken);
74+
}
75+
}
76+
3177
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"profiles": {
3+
"ManagedCode.Storage.AspNetExtensions": {
4+
"commandName": "Project",
5+
"launchBrowser": true,
6+
"environmentVariables": {
7+
"ASPNETCORE_ENVIRONMENT": "Development"
8+
},
9+
"applicationUrl": "https://localhost:59086;http://localhost:59087"
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)