From dc6d4d5ae2d370a3bfbfe7f497325064613e806e Mon Sep 17 00:00:00 2001 From: Hurko Volodymyr Date: Tue, 8 Aug 2023 12:50:13 +0300 Subject: [PATCH] Add methods from StorageFromFileExt and StorageExt --- .../BaseController.cs | 46 +++++++++++++++++++ .../Properties/launchSettings.json | 12 +++++ 2 files changed, 58 insertions(+) create mode 100644 ManagedCode.Storage.AspNetExtensions/Properties/launchSettings.json diff --git a/ManagedCode.Storage.AspNetExtensions/BaseController.cs b/ManagedCode.Storage.AspNetExtensions/BaseController.cs index 137436e..265eb1a 100644 --- a/ManagedCode.Storage.AspNetExtensions/BaseController.cs +++ b/ManagedCode.Storage.AspNetExtensions/BaseController.cs @@ -1,9 +1,13 @@ using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Threading; using System.Threading.Tasks; using ManagedCode.Communication; using ManagedCode.Storage.Core; using ManagedCode.Storage.Core.Models; using Microsoft.AspNetCore.Components.Forms; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace ManagedCode.Storage.AspNetExtensions; @@ -28,4 +32,46 @@ protected async Task>UploadToStorageAsync(IBrowserFile form { return await _storage.UploadToStorageAsync(formFile, options); } + + protected async Task> DownloadAsFileResult(string blobName, CancellationToken cancellationToken = default) + { + return await _storage.DownloadAsFileResult(blobName, cancellationToken); + } + protected async Task> DownloadAsFileResult(BlobMetadata blobMetadata, CancellationToken cancellationToken = default) + { + return await _storage.DownloadAsFileResult(blobMetadata, cancellationToken); + } + + protected async Task> UploadToStorageAsync(IFormFile formFile, + UploadOptions? options = null, + CancellationToken cancellationToken = default) + { + return await _storage.UploadToStorageAsync(formFile, options, cancellationToken); + } + + protected async Task> UploadToStorageAsync(IFormFile formFile, + Action options, + CancellationToken cancellationToken = default) + { + return await _storage.UploadToStorageAsync(formFile, options, cancellationToken); + } + protected async IAsyncEnumerable> UploadToStorageAsync(IFormFileCollection formFiles, + UploadOptions? options = null, + [EnumeratorCancellation] CancellationToken cancellationToken = default) + { + foreach (var formFile in formFiles) + { + yield return await _storage.UploadToStorageAsync(formFile, options, cancellationToken); + } + } + protected async IAsyncEnumerable> UploadToStorageAsync(IFormFileCollection formFiles, + Action options, + [EnumeratorCancellation] CancellationToken cancellationToken = default) + { + foreach (var formFile in formFiles) + { + yield return await _storage.UploadToStorageAsync(formFile, options, cancellationToken); + } + } + } \ No newline at end of file diff --git a/ManagedCode.Storage.AspNetExtensions/Properties/launchSettings.json b/ManagedCode.Storage.AspNetExtensions/Properties/launchSettings.json new file mode 100644 index 0000000..492fcc8 --- /dev/null +++ b/ManagedCode.Storage.AspNetExtensions/Properties/launchSettings.json @@ -0,0 +1,12 @@ +{ + "profiles": { + "ManagedCode.Storage.AspNetExtensions": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:59086;http://localhost:59087" + } + } +} \ No newline at end of file