Skip to content

Blob Storage Endpoints — Admin API

Granit.BlobStorage.Endpoints exposes a Minimal API for managing the full blob lifecycle: initiate uploads (presigned URLs), confirm uploads (validation pipeline), generate download URLs, delete blobs (crypto-shredding), and clean up orphans. All endpoints are protected by the BlobStorage.Admin authorization policy with configurable role requirements.

  • DirectoryGranit.BlobStorage.Endpoints/ Minimal API route groups + DTOs + validators
    • Granit.BlobStorage Core abstractions (IBlobStorage, BlobDescriptor)
    • Granit.BlobStorage.EntityFrameworkCore EF Core persistence + IBlobQueryableProvider
// In your application startup
app.MapBlobStorageEndpoints();
// With custom options:
app.MapBlobStorageEndpoints(opts =>
{
opts.RoutePrefix = "admin/blobs";
opts.RequiredRole = "storage-admin";
opts.TagName = "Storage";
});
OptionDefaultDescription
RoutePrefix"blobs"Route prefix for all blob endpoints
RequiredRole"granit-blobs-admin"Role required for the authorization policy
TagName"BlobStorage"OpenAPI tag name for endpoint grouping

Configuration section: BlobStorageEndpoints.

MethodRouteHandlerDescription
POST/uploadInitiateBlobUploadInitiate a direct-to-cloud upload, returns presigned URL
POST/{id}/confirmConfirmBlobUploadConfirm upload completed, runs validation pipeline
MethodRouteHandlerDescription
GET/{id}GetBlobDescriptorGet a blob descriptor by ID
MethodRouteHandlerDescription
POST/{id}/download-urlGenerateBlobDownloadUrlGenerate a presigned download URL
DELETE/{id}DeleteBlobDelete a blob (crypto-shredding, audit record retained)
POST/cleanup-orphansCleanupOrphanedBlobsClean up orphaned blobs stuck in Pending/Uploading

When Granit.BlobStorage.EntityFrameworkCore is registered, a query endpoint is available:

MethodRouteHandlerDescription
POST/queryQueryBlobDescriptorsFilter, sort, and paginate blob descriptors
DTODirectionUsed by
BlobUploadInitiateRequestInputPOST upload
BlobUploadInitiateResponseOutputPOST upload (includes presigned URL)
BlobConfirmUploadRequestInputPOST confirm
BlobConfirmUploadResponseOutputPOST confirm (includes validation outcome)
BlobDownloadUrlRequestInputPOST download-url
BlobDownloadUrlResponseOutputPOST download-url (includes presigned URL)
BlobDeleteRequestInputDELETE
BlobDescriptorResponseOutputGET by ID
BlobCleanupOrphansResponseOutputPOST cleanup-orphans

All endpoints require the BlobStorage.Admin authorization policy. Granular permissions are defined in BlobStoragePermissions:

PermissionDescription
BlobStorage.Blobs.ViewView blob descriptors
BlobStorage.Blobs.UploadUpload blobs
BlobStorage.Blobs.DownloadDownload blobs
BlobStorage.Blobs.DeleteDelete blobs
BlobStorage.Blobs.ManageManage blobs (confirm uploads, cleanup orphans)

All request DTOs are automatically validated via FluentValidation through MapGranitGroup(). Key rules:

  • Container names: lowercase alphanumeric with hyphens, max 128 chars
  • File names: non-empty, max 1024 chars
  • Content types: valid MIME format (type/subtype)
  • File size: must be positive
  • Deletion reason: max 500 chars (optional)