Skip to content

Azure Blob Storage Uploads

Shiny HTTP Transfers includes a built-in fluent builder for uploading files to Azure Blob Storage. The AzureBlobStorageUploadRequest handles all Azure-specific headers and authentication, producing a standard HttpTransferRequest that runs as a background transfer.

IHttpTransferManager manager; // injected
var request = new AzureBlobStorageUploadRequest("/path/to/file.pdf")
.WithBlobContainer("myaccount", "mycontainer")
.WithSasToken("sv=2023-01-01&ss=b&srt=o&sp=w&se=2026-12-31&sig=...")
.Build();
await manager.Queue(request);

Azure Blob Storage supports two authentication methods.

A Shared Access Signature provides scoped, time-limited access without exposing your storage account key.

var request = new AzureBlobStorageUploadRequest("/path/to/file.pdf")
.WithBlobContainer("myaccount", "mycontainer")
.WithSasToken("sv=2023-01-01&ss=b&srt=o&sp=w&se=2026-12-31&sig=abc123")
.Build();

The SAS token is appended as a query string to the blob URL.

For server-side or trusted environments where the storage key is available.

var request = new AzureBlobStorageUploadRequest("/path/to/file.pdf")
.WithBlobContainer("myaccount", "mycontainer")
.WithSharedKeyAuthorization("your-shared-key")
.Build();

This adds Authorization, x-ms-date, and x-ms-version headers automatically.

MethodDescription
WithBlobContainer(tenant, container)Sets the URI to https://{tenant}.blob.core.windows.net/{container}
WithCustomUri(uri)Use a custom Azure endpoint URL
WithSasToken(token)Authenticate with a SAS token
WithSharedKeyAuthorization(key, version?, date?)Authenticate with a shared key
WithRemoteFileName(name)Set the blob name (defaults to local filename)
WithMeteredConnection()Allow upload on metered/cellular networks
WithHeader(key, value)Add a custom HTTP header
PropertyTypeDescription
LocalFilePathstringPath to the file being uploaded
Identifierstring?Transfer identifier (auto-generated if not set)
Uristring?Target blob URL
RemoteFileNamestring?Blob name (defaults to local filename)
UseMeteredConnectionboolAllow metered network transfers
HeadersDictionary<string, string>Custom headers

When Build() is called, these headers are automatically set:

HeaderValue
Content-LengthFile size in bytes
x-ms-blob-typeBlockBlob
Content-Dispositionattachment; filename="{name}"
IHttpTransferManager manager; // injected
var builder = new AzureBlobStorageUploadRequest("/path/to/photo.jpg")
.WithBlobContainer("mystorageaccount", "uploads")
.WithSasToken("sv=2023-01-01&ss=b&srt=o&sp=w&se=2026-12-31&sig=abc123")
.WithRemoteFileName("photos/vacation.jpg")
.WithMeteredConnection();
var request = builder.Build();
var transfer = await manager.Queue(request);

Use HttpTransferDelegate to handle token expiration during long uploads.

public partial class MyTransferDelegate(
ILogger<MyTransferDelegate> logger,
IHttpTransferManager manager,
ISasTokenService tokenService
) : HttpTransferDelegate(logger, manager, maxErrorRetries: 3)
{
protected override async Task<HttpTransferRequest?> OnAuthorizationFailed(
HttpTransferRequest request,
int retries
)
{
if (retries > 3)
return null; // give up
var newToken = await tokenService.GetFreshSasTokenAsync();
// Rebuild the URI with the new token
var baseUri = request.Uri.Split('?')[0];
return request with { Uri = $"{baseUri}?{newToken}" };
}
}