Class AzureBlobStorage
- All Implemented Interfaces:
ObjectStorage
Azure Blob Storage, through its REST API, with no Azure library. A bucket here is a container and an object a block blob.
Two ways to authenticate:
- An account key (Shared Key), from the key itself or a connection string. Presigned URLs are service SAS tokens computed here.
- A managed identity (Microsoft Entra ID), on an Azure VM, App Service, Container Apps or Functions, with no secret on the machine. The identity needs a data-plane role such as "Storage Blob Data Contributor". Presigned URLs are then user-delegation SAS tokens, which costs one call to fetch a delegation key a day.
forConnectionString(String) with UseDevelopmentStorage=true talks to a local
Azurite.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class -
Method Summary
Modifier and TypeMethodDescriptionvoidcreateBucket(String bucket) Creates a bucket, and says nothing when this account already owns it.voiddeleteObject(String bucket, String key) Deletes an object.static AzureBlobStorageforAccountKey(String account, String key) The accountaccount, authenticated with its base64 access key.static AzureBlobStorageforConnectionString(String connectionString) The account a connection string from the Azure portal names, or Azurite forUseDevelopmentStorage=true.static AzureBlobStorageforManagedIdentity(String account, String clientId) The accountaccount, authenticated as the machine's managed identity.getName()The provider's short name:s3(Amazon S3 and every S3-compatible endpoint, R2 included),gcs,azureormemory.byte[]Downloads an object.headObject(String bucket, String key) The object's metadata, or null when it does not exist.listObjects(String bucket, String prefix, int max) Up tomaxkeys underprefix(null or empty for all), following the provider's pagination until the listing ends ormaxis reached.presignGet(String bucket, String key, int seconds) A URL that downloads the object with no credentials, forseconds.presignPut(String bucket, String key, int seconds) The upload counterpart: a URL a client canPUTthe bytes to, forseconds.Uploads an object, replacing one of the same key.withEndpoint(String endpoint) The same account and credentials at another endpoint: a sovereign cloud (https://<account>.blob.core.chinacloudapi.cn), a private endpoint, or an emulator, whose URL then includes the account path.
-
Method Details
-
forAccountKey
The accountaccount, authenticated with its base64 access key. -
forManagedIdentity
The accountaccount, authenticated as the machine's managed identity.clientIdpicks a user-assigned identity; null takes the system one. -
forConnectionString
The account a connection string from the Azure portal names, or Azurite forUseDevelopmentStorage=true. It must carry anAccountKey; a connection string holding only a SAS is not supported.- Throws:
IOException- when the string names no account or key
-
withEndpoint
The same account and credentials at another endpoint: a sovereign cloud (https://<account>.blob.core.chinacloudapi.cn), a private endpoint, or an emulator, whose URL then includes the account path. -
getName
Description copied from interface:ObjectStorageThe provider's short name:s3(Amazon S3 and every S3-compatible endpoint, R2 included),gcs,azureormemory.- Specified by:
getNamein interfaceObjectStorage
-
createBucket
Description copied from interface:ObjectStorageCreates a bucket, and says nothing when this account already owns it.
Usually infrastructure's job, but a first run against an emulator or a test fixture needs it.
- Specified by:
createBucketin interfaceObjectStorage- Throws:
IOException
-
putObject
public String putObject(String bucket, String key, byte[] content, String contentType) throws IOException Description copied from interface:ObjectStorageUploads an object, replacing one of the same key. Returns its ETag, the provider's receipt for exactly these bytes.
contentTypemay be null, which storesapplication/octet-stream.- Specified by:
putObjectin interfaceObjectStorage- Throws:
IOException
-
getObject
Description copied from interface:ObjectStorageDownloads an object. Throws when it is missing, rather than returning null.- Specified by:
getObjectin interfaceObjectStorage- Throws:
IOException
-
headObject
Description copied from interface:ObjectStorageThe object's metadata, or null when it does not exist.- Specified by:
headObjectin interfaceObjectStorage- Throws:
IOException
-
deleteObject
Description copied from interface:ObjectStorageDeletes an object. Deleting one that is not there is not an error.- Specified by:
deleteObjectin interfaceObjectStorage- Throws:
IOException
-
listObjects
Description copied from interface:ObjectStorageUp tomaxkeys underprefix(null or empty for all), following the provider's pagination until the listing ends ormaxis reached. Zero answers an empty list; a negativemaxis refused.- Specified by:
listObjectsin interfaceObjectStorage- Throws:
IOException
-
presignGet
Description copied from interface:ObjectStorageA URL that downloads the object with no credentials, for
seconds.Computed, not requested, wherever the provider allows it: the URL can be handed straight to a client. A lifetime the provider refuses -- zero or less, or past seven days on S3, R2 and GCS -- throws an IOException on every provider, so moving between them does not change how it fails.
- Specified by:
presignGetin interfaceObjectStorage- Throws:
IOException
-
presignPut
Description copied from interface:ObjectStorageThe upload counterpart: a URL a client can
PUTthe bytes to, forseconds.Azure needs one header on that
PUTthat the others do not:x-ms-blob-type: BlockBlob. A client that serves more than one provider can send it everywhere; S3 and GCS ignore it.- Specified by:
presignPutin interfaceObjectStorage- Throws:
IOException
-