Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions ManagedCode.Storage.AspNetExtensions/BaseController.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -28,4 +32,46 @@ protected async Task<Result<BlobMetadata>>UploadToStorageAsync(IBrowserFile form
{
return await _storage.UploadToStorageAsync(formFile, options);
}

protected async Task<Result<FileResult>> DownloadAsFileResult(string blobName, CancellationToken cancellationToken = default)
{
return await _storage.DownloadAsFileResult(blobName, cancellationToken);
}
protected async Task<Result<FileResult>> DownloadAsFileResult(BlobMetadata blobMetadata, CancellationToken cancellationToken = default)
{
return await _storage.DownloadAsFileResult(blobMetadata, cancellationToken);
}

protected async Task<Result<BlobMetadata>> UploadToStorageAsync(IFormFile formFile,
UploadOptions? options = null,
CancellationToken cancellationToken = default)
{
return await _storage.UploadToStorageAsync(formFile, options, cancellationToken);
}

protected async Task<Result<BlobMetadata>> UploadToStorageAsync(IFormFile formFile,
Action<UploadOptions> options,
CancellationToken cancellationToken = default)
{
return await _storage.UploadToStorageAsync(formFile, options, cancellationToken);
}
protected async IAsyncEnumerable<Result<BlobMetadata>> 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<Result<BlobMetadata>> UploadToStorageAsync(IFormFileCollection formFiles,
Action<UploadOptions> options,
[EnumeratorCancellation] CancellationToken cancellationToken = default)
{
foreach (var formFile in formFiles)
{
yield return await _storage.UploadToStorageAsync(formFile, options, cancellationToken);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"profiles": {
"ManagedCode.Storage.AspNetExtensions": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:59086;http://localhost:59087"
}
}
}