AugusteVN.Azure.BlobStorage
1.1.0
dotnet add package AugusteVN.Azure.BlobStorage --version 1.1.0
NuGet\Install-Package AugusteVN.Azure.BlobStorage -Version 1.1.0
<PackageReference Include="AugusteVN.Azure.BlobStorage" Version="1.1.0" />
<PackageVersion Include="AugusteVN.Azure.BlobStorage" Version="1.1.0" />
<PackageReference Include="AugusteVN.Azure.BlobStorage" />
paket add AugusteVN.Azure.BlobStorage --version 1.1.0
#r "nuget: AugusteVN.Azure.BlobStorage, 1.1.0"
#:package AugusteVN.Azure.BlobStorage@1.1.0
#addin nuget:?package=AugusteVN.Azure.BlobStorage&version=1.1.0
#tool nuget:?package=AugusteVN.Azure.BlobStorage&version=1.1.0
Azure Blob Storage
Upload a file to Azure Blob Storage or generate a SAS URL.
Configuration
appsettings.json
{
"BlobStorageConfig": {
"ConnectionString": "<to-fill>",
"AccountName": "<to-fill>",
"AccountKey": "<to-fill-optional>"
}
}
Program.cs
builder.Services
.AddOptions<BlobStorageConfig>()
.BindConfiguration(nameof(BlobStorageConfig));
builder.Services.AddSingleton<IBlobStorageClient, BlobStorageClient>();
// Or initialize
var blobStorageClient = new BlobStorageClient(
new BlobStorageConfig {
ConnectionString = "<to-fill>",
AccountName = "<to-fill>",
AccountKey = "<to-fill-optional>" // To generate URLs with SAS tokens.
});
Upload File
Program.cs
app.MapPost("/", async (IFormFile file, IBlobStorageClient blobStorageClient) => {
var url = await blobStorageClient.UploadSingleAsync(
"targetContainerName"
file.FileName,
file.OpenReadStream()
);
return Results.Ok(new { Url = url });
});
Generate URL with SAS token
Generates an URL including a SAS token that grants read access for a given duration.
This requires the AccountKey to be configured in the appsettings.json.
Program.cs
app.MapGet("/", (IBlobStorageClient blobStorageClient) => {
var sasUrl = await blobStorageClient.GenerateSasUrlForBlob(
containerName: "targetContainerName",
blobName: "example.png",
expiresOn: DateTimeOffset.UtcNow.AddHours(24) // <-- default value
);
return Results.Ok(new { Url = sasUrl });
});
To see it in action, watch: File Upload - Blazor to Minimal API to Azure with C# .NET 8.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Azure.Storage.Blobs (>= 12.29.1)
- Microsoft.Extensions.Options (>= 10.0.3)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on AugusteVN.Azure.BlobStorage:
| Package | Downloads |
|---|---|
|
AugusteVN.Modules.Commerce.Api
Minimal API endpoints for products and shop orders |
|
|
AugusteVN.Modules.Blog.Api
Minimal API endpoints for blog posts and RSS feeds |
|
|
AugusteVN.Modules.Files.Api
Minimal API endpoint for file uploads to Azure Blob Storage |
GitHub repositories
This package is not used by any popular GitHub repositories.
Upgraded to .NET 10.