Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit f080807
Author: ksemenenko <[email protected]>
Date:   Sun Jul 17 19:13:54 2022 +0200

    datalake

commit 43f7b03
Author: ksemenenko <[email protected]>
Date:   Sun Jul 17 15:43:05 2022 +0200

    datalake

commit e9c604f
Author: ksemenenko <[email protected]>
Date:   Sat Jul 16 19:27:02 2022 +0200

    gcp

commit e18ab70
Author: ksemenenko <[email protected]>
Date:   Sat Jul 16 14:03:56 2022 +0200

    FileSystem

commit 6864e17
Author: ksemenenko <[email protected]>
Date:   Sat Jul 16 12:31:31 2022 +0200

    aws

commit 23c5105
Author: ksemenenko <[email protected]>
Date:   Fri Jul 15 22:50:20 2022 +0200

    Azure

commit b4ba75e
Author: ksemenenko <[email protected]>
Date:   Fri Jul 15 21:29:14 2022 +0200

    new api

commit eba7dc3
Author: ksemenenko <[email protected]>
Date:   Sat Jun 18 18:18:03 2022 +0200

    IStorageManager

commit bbc7d2d
Author: ksemenenko <[email protected]>
Date:   Mon May 9 22:41:18 2022 +0200

    mimetypes
  • Loading branch information
KSemenenko committed Jul 17, 2022
1 parent 24c631a commit f0ce4d5
Show file tree
Hide file tree
Showing 45 changed files with 1,765 additions and 2,796 deletions.
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Product>Managed Code - Storage</Product>
<Version>1.2.0</Version>
<PackageVersion>1.2.0</PackageVersion>
<Version>1.2.1</Version>
<PackageVersion>1.2.1</PackageVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
Expand Down
25 changes: 14 additions & 11 deletions ManagedCode.Storage.AspNetExtensions/StorageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,25 @@ public static async Task<BlobMetadata> UploadToStorageAsync(this IStorage storag

BlobMetadata blobMetadata = new()
{
Name = options.UseRandomName ? $"{Guid.NewGuid().ToString("N").ToLowerInvariant()}{extension}" : formFile.FileName,
ContentType = formFile.ContentType,
Rewrite = options.Rewrite
Name = options.UseRandomName ? "" : formFile.FileName,
MimeType = formFile.ContentType,
};

if (formFile.Length > MinLengthForLargeFile)
{
var localFile = await formFile.ToLocalFileAsync(cancellationToken);

await storage.UploadStreamAsync(blobMetadata, localFile.FileStream, cancellationToken);
await storage.UploadAsync(localFile.FileInfo, cancellationToken);
}
else
{
using (var stream = formFile.OpenReadStream())
{
await storage.UploadStreamAsync(blobMetadata, stream, cancellationToken);
await storage.UploadAsync(stream, uploadOptions =>
{
uploadOptions.FileName = options.UseRandomName ? "" : formFile.FileName;
uploadOptions.MimeType = formFile.ContentType;

} , cancellationToken);
}
}

Expand All @@ -67,25 +70,25 @@ public static async IAsyncEnumerable<BlobMetadata> UploadToStorageAsync(this ISt
return null;
}

return new FileStreamResult(localFile.FileStream, MimeHelper.GetMimeType(localFile.FileInfo.Extension))
return new FileStreamResult(localFile.Value.FileStream, MimeHelper.GetMimeType(localFile.Value.FileInfo.Extension))
{
FileDownloadName = localFile.FileName
FileDownloadName = localFile.Value.FileName
};
}

public static async Task<FileResult?> DownloadAsFileResult(this IStorage storage, BlobMetadata blobMetadata,
CancellationToken cancellationToken = default)
{
var localFile = await storage.DownloadAsync(blobMetadata, cancellationToken);
var localFile = await storage.DownloadAsync(blobMetadata.Name, cancellationToken);

if (localFile is null)
{
return null;
}

return new FileStreamResult(localFile.FileStream, MimeHelper.GetMimeType(localFile.FileInfo.Extension))
return new FileStreamResult(localFile.Value.FileStream, MimeHelper.GetMimeType(localFile.Value.FileInfo.Extension))
{
FileDownloadName = localFile.FileName
FileDownloadName = localFile.Value.FileName
};
}
}
Loading

0 comments on commit f0ce4d5

Please sign in to comment.