BlobContainerAsyncClient Class
- java.
lang. Object - com.
azure. storage. blob. BlobContainerAsyncClient
- com.
public final class BlobContainerAsyncClient
Client to a container. It may only be instantiated through a BlobContainerClientBuilder or via the method getBlobContainerAsyncClient(String containerName). This class does not hold any state about a particular blob but is instead a convenient way of sending off appropriate requests to the resource on the service. It may also be used to construct URLs to blobs.
This client contains operations on a container. Operations on a blob are available on BlobAsyncClient through getBlobAsyncClient(String blobName), and operations on the service are available on BlobServiceAsyncClient.
Please refer to the Azure Docs for more information on containers.
Note this client is an async client that returns reactive responses from Spring Reactor Core project (https://projectreactor.io/). Calling the methods in this client will NOT start the actual network operation, until .subscribe()
is called on the reactive response. You can simply convert one of these responses to a CompletableFuture object through Mono#toFuture().
Field Summary
Modifier and Type | Field and Description |
---|---|
static final String |
LOG_CONTAINER_NAME
Special container name for the logs container in the Storage account. |
static final String |
ROOT_CONTAINER_NAME
Special container name for the root container in the Storage account. |
static final String |
STATIC_WEBSITE_CONTAINER_NAME
Special container name for the static website container in the Storage account. |
Method Summary
Methods inherited from java.lang.Object
Field Details
LOG_CONTAINER_NAME
public static final String LOG_CONTAINER_NAME
Special container name for the logs container in the Storage account.
ROOT_CONTAINER_NAME
public static final String ROOT_CONTAINER_NAME
Special container name for the root container in the Storage account.
STATIC_WEBSITE_CONTAINER_NAME
public static final String STATIC_WEBSITE_CONTAINER_NAME
Special container name for the static website container in the Storage account.
Method Details
create
public Mono
Creates a new container within a storage account. If a container with the same name already exists, the operation fails. For more information, see the Azure Docs.
Code Samples
client.create().subscribe(
response -> System.out.printf("Create completed%n"),
error -> System.out.printf("Error while creating container %s%n", error));
Returns:
createIfNotExists
public Mono
Creates a new container within a storage account if it does not exist. For more information, see the Azure Docs.
Code Samples
client.createIfNotExists().subscribe(created -> {
if (created) {
System.out.println("successfully created.");
} else {
System.out.println("Already exists.");
}
});
Returns:
true
indicates a new container was created,
true
indicates a container already existed at this location.createIfNotExistsWithResponse
public Mono
Creates a new container within a storage account if it does not exist. For more information, see the Azure Docs.
Code Samples
Map<String, String> metadata = Collections.singletonMap("metadata", "value");
BlobContainerCreateOptions options = new BlobContainerCreateOptions().setMetadata(metadata)
.setPublicAccessType(PublicAccessType.CONTAINER);
client.createIfNotExistsWithResponse(options).subscribe(response -> {
if (response.getStatusCode() == 409) {
System.out.println("Already exists.");
} else {
System.out.println("successfully created.");
}
});
Parameters:
Returns:
createWithResponse
public Mono
Creates a new container within a storage account. If a container with the same name already exists, the operation fails. For more information, see the Azure Docs.
Code Samples
Map<String, String> metadata = Collections.singletonMap("metadata", "value");
client.createWithResponse(metadata, PublicAccessType.CONTAINER).subscribe(response ->
System.out.printf("Create completed with status %d%n", response.getStatusCode()));
Parameters:
Returns:
delete
public Mono
Marks the specified container for deletion. The container and any blobs contained within it are later deleted during garbage collection. For more information, see the Azure Docs.
Code Samples
client.delete().subscribe(
response -> System.out.printf("Delete completed%n"),
error -> System.out.printf("Delete failed: %s%n", error));
Returns:
deleteIfExists
public Mono
Marks the specified container for deletion if it exists. The container and any blobs contained within it are later deleted during garbage collection. For more information, see the Azure Docs.
Code Samples
client.deleteIfExists().subscribe(deleted -> {
if (deleted) {
System.out.println("Successfully deleted.");
} else {
System.out.println("Does not exist.");
}
});
Returns:
true
indicates the container was deleted,
false
indicates the container does not exist.deleteIfExistsWithResponse
public Mono
Marks the specified container for deletion if it exists. The container and any blobs contained within it are later deleted during garbage collection. For more information, see the Azure Docs.
Code Samples
BlobRequestConditions requestConditions = new BlobRequestConditions()
.setLeaseId(leaseId)
.setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
client.deleteIfExistsWithResponse(requestConditions).subscribe(response -> {
if (response.getStatusCode() == 404) {
System.out.println("Does not exist.");
} else {
System.out.println("successfully deleted.");
}
});
Parameters:
Returns:
deleteWithResponse
public Mono
Marks the specified container for deletion. The container and any blobs contained within it are later deleted during garbage collection. For more information, see the Azure Docs.
Code Samples
BlobRequestConditions requestConditions = new BlobRequestConditions()
.setLeaseId(leaseId)
.setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
client.deleteWithResponse(requestConditions).subscribe(response ->
System.out.printf("Delete completed with status %d%n", response.getStatusCode()));
Parameters:
Returns:
exists
public Mono
Gets if the container this client represents exists in the cloud.
Code Samples
client.exists().subscribe(response -> System.out.printf("Exists? %b%n", response));
Returns:
existsWithResponse
public Mono
Gets if the container this client represents exists in the cloud.
Code Samples
client.existsWithResponse().subscribe(response -> System.out.printf("Exists? %b%n", response.getValue()));
Returns:
findBlobsByTags
public PagedFlux
Returns a reactive Publisher emitting the blobs in this container whose tags match the query expression. For more information, including information on the query syntax, see the Azure Docs.
Code Samples
client.findBlobsByTags(new FindBlobsOptions("where=tag=value").setMaxResultsPerPage(10))
.subscribe(blob -> System.out.printf("Name: %s%n", blob.getName()));
Parameters:
Returns:
findBlobsByTags
public PagedFlux
Returns a reactive Publisher emitting the blobs in this container whose tags match the query expression. For more information, including information on the query syntax, see the Azure Docs.
Code Samples
client.findBlobsByTags("where=tag=value").subscribe(blob -> System.out.printf("Name: %s%n", blob.getName()));
Parameters:
Returns:
generateSas
public String generateSas(BlobServiceSasSignatureValues blobServiceSasSignatureValues)
Generates a service SAS for the container using the specified BlobServiceSasSignatureValues
Note : The client must be authenticated via StorageSharedKeyCredential
See BlobServiceSasSignatureValues for more information on how to construct a service SAS.
Code Samples
OffsetDateTime expiryTime = OffsetDateTime.now().plusDays(1);
BlobContainerSasPermission permission = new BlobContainerSasPermission().setReadPermission(true);
BlobServiceSasSignatureValues values = new BlobServiceSasSignatureValues(expiryTime, permission)
.setStartTime(OffsetDateTime.now());
client.generateSas(values); // Client must be authenticated via StorageSharedKeyCredential
Parameters:
Returns:
String
representing the SAS query parameters.generateSas
public String generateSas(BlobServiceSasSignatureValues blobServiceSasSignatureValues, Context context)
Generates a service SAS for the container using the specified BlobServiceSasSignatureValues
Note : The client must be authenticated via StorageSharedKeyCredential
See BlobServiceSasSignatureValues for more information on how to construct a service SAS.
Code Samples
OffsetDateTime expiryTime = OffsetDateTime.now().plusDays(1);
BlobContainerSasPermission permission = new BlobContainerSasPermission().setReadPermission(true);
BlobServiceSasSignatureValues values = new BlobServiceSasSignatureValues(expiryTime, permission)
.setStartTime(OffsetDateTime.now());
// Client must be authenticated via StorageSharedKeyCredential
client.generateSas(values, new Context("key", "value"));
Parameters:
Returns:
String
representing the SAS query parameters.generateSas
public String generateSas(BlobServiceSasSignatureValues blobServiceSasSignatureValues, Consumer
Generates a service SAS for the container using the specified BlobServiceSasSignatureValues
Note : The client must be authenticated via StorageSharedKeyCredential
See BlobServiceSasSignatureValues for more information on how to construct a service SAS.
Parameters:
Returns:
String
representing the SAS query parameters.generateUserDelegationSas
public String generateUserDelegationSas(BlobServiceSasSignatureValues blobServiceSasSignatureValues, UserDelegationKey userDelegationKey)
Generates a user delegation SAS for the container using the specified BlobServiceSasSignatureValues.
See BlobServiceSasSignatureValues for more information on how to construct a user delegation SAS.
Code Samples
OffsetDateTime myExpiryTime = OffsetDateTime.now().plusDays(1);
BlobContainerSasPermission myPermission = new BlobContainerSasPermission().setReadPermission(true);
BlobServiceSasSignatureValues myValues = new BlobServiceSasSignatureValues(expiryTime, permission)
.setStartTime(OffsetDateTime.now());
client.generateUserDelegationSas(values, userDelegationKey);
Parameters:
Returns:
String
representing the SAS query parameters.generateUserDelegationSas
public String generateUserDelegationSas(BlobServiceSasSignatureValues blobServiceSasSignatureValues, UserDelegationKey userDelegationKey, String accountName, Context context)
Generates a user delegation SAS for the container using the specified BlobServiceSasSignatureValues.
See BlobServiceSasSignatureValues for more information on how to construct a user delegation SAS.
Code Samples
OffsetDateTime myExpiryTime = OffsetDateTime.now().plusDays(1);
BlobContainerSasPermission myPermission = new BlobContainerSasPermission().setReadPermission(true);
BlobServiceSasSignatureValues myValues = new BlobServiceSasSignatureValues(expiryTime, permission)
.setStartTime(OffsetDateTime.now());
client.generateUserDelegationSas(values, userDelegationKey, accountName, new Context("key", "value"));
Parameters:
Returns:
String
representing the SAS query parameters.generateUserDelegationSas
public String generateUserDelegationSas(BlobServiceSasSignatureValues blobServiceSasSignatureValues, UserDelegationKey userDelegationKey, String accountName, Consumer
Generates a user delegation SAS for the container using the specified BlobServiceSasSignatureValues.
See BlobServiceSasSignatureValues for more information on how to construct a user delegation SAS.
Parameters:
Returns:
String
representing the SAS query parameters.getAccessPolicy
public Mono
Returns the container's permissions. The permissions indicate whether container's blobs may be accessed publicly. For more information, see the Azure Docs.
Code Samples
client.getAccessPolicy().subscribe(response -> {
System.out.printf("Blob Access Type: %s%n", response.getBlobAccessType());
for (BlobSignedIdentifier identifier : response.getIdentifiers()) {
System.out.printf("Identifier Name: %s, Permissions %s%n",
identifier.getId(),
identifier.getAccessPolicy().getPermissions());
}
});
Returns:
getAccessPolicyWithResponse
public Mono
Returns the container's permissions. The permissions indicate whether container's blobs may be accessed publicly. For more information, see the Azure Docs.
Code Samples
client.getAccessPolicyWithResponse(leaseId).subscribe(response -> {
System.out.printf("Blob Access Type: %s%n", response.getValue().getBlobAccessType());
for (BlobSignedIdentifier identifier : response.getValue().getIdentifiers()) {
System.out.printf("Identifier Name: %s, Permissions %s%n",
identifier.getId(),
identifier.getAccessPolicy().getPermissions());
}
});
Parameters:
Returns:
getAccountInfo
public Mono
Returns the sku name and account kind for the account. For more information, please see the Azure Docs.
Code Samples
client.getAccountInfo().subscribe(response ->
System.out.printf("Account Kind: %s, SKU: %s%n",
response.getAccountKind(),
response.getSkuName()));
Returns:
getAccountInfoWithResponse
public Mono
Returns the sku name and account kind for the account. For more information, please see the Azure Docs.
Code Samples
client.getAccountInfoWithResponse().subscribe(response ->
System.out.printf("Account Kind: %s, SKU: %s%n",
response.getValue().getAccountKind(),
response.getValue().getSkuName()));
Returns:
getAccountName
public String getAccountName()
Get associated account name.
Returns:
getAccountUrl
public String getAccountUrl()
Get the url of the storage account.
Returns:
getBlobAsyncClient
public BlobAsyncClient getBlobAsyncClient(String blobName)
Creates a new BlobAsyncClient object by concatenating blobName to the end of ContainerAsyncClient's URL. The new BlobAsyncClient uses the same request policy pipeline as the ContainerAsyncClient.
Code Samples
BlobAsyncClient blobAsyncClient = client.getBlobAsyncClient(blobName);
Parameters:
String
representing the name of the blob. If the blob name contains special characters,
pass in the url encoded version of the blob name.
Returns:
getBlobAsyncClient
public BlobAsyncClient getBlobAsyncClient(String blobName, String snapshot)
Creates a new BlobAsyncClient object by concatenating blobName to the end of ContainerAsyncClient's URL. The new BlobAsyncClient uses the same request policy pipeline as the ContainerAsyncClient.
Code Samples
BlobAsyncClient blobAsyncClient = client.getBlobAsyncClient(blobName, snapshot);
Parameters:
String
representing the name of the blob. If the blob name contains special characters,
pass in the url encoded version of the blob name.
Returns:
getBlobContainerName
public String getBlobContainerName()
Get the container name.
Code Samples
String containerName = client.getBlobContainerName();
System.out.println("The name of the blob is " + containerName);
Returns:
getBlobContainerUrl
public String getBlobContainerUrl()
Gets the URL of the container represented by this client.
Returns:
getBlobVersionAsyncClient
public BlobAsyncClient getBlobVersionAsyncClient(String blobName, String versionId)
Creates a new BlobAsyncClient object by concatenating blobName to the end of ContainerAsyncClient's URL. The new BlobAsyncClient uses the same request policy pipeline as the ContainerAsyncClient.
Parameters:
String
representing the name of the blob. If the blob name contains special characters,
pass in the url encoded version of the blob name.
null
to interact with the latest blob version.
Returns:
getCustomerProvidedKey
public CpkInfo getCustomerProvidedKey()
Gets the CpkInfo associated with this client that will be passed to BlobAsyncClient when getBlobAsyncClient(String blobName) is called.
Returns:
getEncryptionScope
public String getEncryptionScope()
Gets the EncryptionScope used to encrypt this blob's content on the server.
Returns:
getHttpPipeline
public HttpPipeline getHttpPipeline()
Gets the HttpPipeline powering this client.
Returns:
getProperties
public Mono
Returns the container's metadata and system properties. For more information, see the Azure Docs.
Code Samples
client.getProperties().subscribe(response ->
System.out.printf("Public Access Type: %s, Legal Hold? %b, Immutable? %b%n",
response.getBlobPublicAccess(),
response.hasLegalHold(),
response.hasImmutabilityPolicy()));
Returns:
getPropertiesWithResponse
public Mono
Returns the container's metadata and system properties. For more information, see the Azure Docs.
Code Samples
client.getPropertiesWithResponse(leaseId).subscribe(response ->
System.out.printf("Public Access Type: %s, Legal Hold? %b, Immutable? %b%n",
response.getValue().getBlobPublicAccess(),
response.getValue().hasLegalHold(),
response.getValue().hasImmutabilityPolicy()));
Parameters:
Returns:
getServiceAsyncClient
public BlobServiceAsyncClient getServiceAsyncClient()
Get an async client pointing to the account.
Returns:
getServiceVersion
public BlobServiceVersion getServiceVersion()
Gets the service version the client is using.
Returns:
listBlobs
public PagedFlux
Returns a reactive Publisher emitting all the blobs in this container lazily as needed. The directories are flattened and only actual blobs and no directories are returned.
Blob names are returned in lexicographic order. For more information, see the Azure Docs.
E.g. listing a container containing a 'foo' folder, which contains blobs 'foo1' and 'foo2', and a blob on the root level 'bar', will return
- foo/foo1
- foo/foo2
- bar
Code Samples
client.listBlobs().subscribe(blob ->
System.out.printf("Name: %s, Directory? %b%n", blob.getName(), blob.isPrefix()));
Returns:
listBlobs
public PagedFlux
Returns a reactive Publisher emitting all the blobs in this container lazily as needed. The directories are flattened and only actual blobs and no directories are returned.
Blob names are returned in lexicographic order. For more information, see the Azure Docs.
E.g. listing a container containing a 'foo' folder, which contains blobs 'foo1' and 'foo2', and a blob on the root level 'bar', will return
- foo/foo1
- foo/foo2
- bar
ListBlobsOptions options = new ListBlobsOptions()
.setPrefix("prefixToMatch")
.setDetails(new BlobListDetails()
.setRetrieveDeletedBlobs(true)
.setRetrieveSnapshots(true));
client.listBlobs(options).subscribe(blob ->
System.out.printf("Name: %s, Directory? %b, Deleted? %b, Snapshot ID: %s%n",
blob.getName(),
blob.isPrefix(),
blob.isDeleted(),
blob.getSnapshot()));
Parameters:
Returns:
listBlobs
public PagedFlux
Returns a reactive Publisher emitting all the blobs in this container lazily as needed. The directories are flattened and only actual blobs and no directories are returned.
Blob names are returned in lexicographic order. For more information, see the Azure Docs.
E.g. listing a container containing a 'foo' folder, which contains blobs 'foo1' and 'foo2', and a blob on the root level 'bar', will return
- foo/foo1
- foo/foo2
- bar
ListBlobsOptions options = new ListBlobsOptions()
.setPrefix("prefixToMatch")
.setDetails(new BlobListDetails()
.setRetrieveDeletedBlobs(true)
.setRetrieveSnapshots(true));
String continuationToken = "continuationToken";
client.listBlobs(options, continuationToken).subscribe(blob ->
System.out.printf("Name: %s, Directory? %b, Deleted? %b, Snapshot ID: %s%n",
blob.getName(),
blob.isPrefix(),
blob.isDeleted(),
blob.getSnapshot()));
Parameters:
Returns:
listBlobsByHierarchy
public PagedFlux
Returns a reactive Publisher emitting all the blobs and directories (prefixes) under the given directory (prefix). Directories will have isPrefix() set to true.
Blob names are returned in lexicographic order. For more information, see the Azure Docs.
E.g. listing a container containing a 'foo' folder, which contains blobs 'foo1' and 'foo2', and a blob on the root level 'bar', will return the following results when prefix=null:
- foo/ (isPrefix = true)
- bar (isPrefix = false)
will return the following results when prefix="foo/":
- foo/foo1 (isPrefix = false)
- foo/foo2 (isPrefix = false)
Code Samples
client.listBlobsByHierarchy("directoryName").subscribe(blob ->
System.out.printf("Name: %s, Directory? %b%n", blob.getName(), blob.isDeleted()));
Parameters:
Returns:
listBlobsByHierarchy
public PagedFlux
Returns a reactive Publisher emitting all the blobs and prefixes (directories) under the given prefix (directory). Directories will have isPrefix() set to true.
Blob names are returned in lexicographic order. For more information, see the Azure Docs.
E.g. listing a container containing a 'foo' folder, which contains blobs 'foo1' and 'foo2', and a blob on the root level 'bar', will return the following results when prefix=null:
- foo/ (isPrefix = true)
- bar (isPrefix = false)
will return the following results when prefix="foo/":
- foo/foo1 (isPrefix = false)
- foo/foo2 (isPrefix = false)
Code Samples
ListBlobsOptions options = new ListBlobsOptions()
.setPrefix("directoryName")
.setDetails(new BlobListDetails()
.setRetrieveDeletedBlobs(true)
.setRetrieveSnapshots(true));
client.listBlobsByHierarchy("/", options).subscribe(blob ->
System.out.printf("Name: %s, Directory? %b, Deleted? %b, Snapshot ID: %s%n",
blob.getName(),
blob.isPrefix(),
blob.isDeleted(),
blob.getSnapshot()));
Parameters:
Returns:
setAccessPolicy
public Mono
Sets the container's permissions. The permissions indicate whether blobs in a container may be accessed publicly. Note that, for each signed identifier, we will truncate the start and expiry times to the nearest second to ensure the time formatting is compatible with the service. For more information, see the Azure Docs.
Code Samples
BlobSignedIdentifier identifier = new BlobSignedIdentifier()
.setId("name")
.setAccessPolicy(new BlobAccessPolicy()
.setStartsOn(OffsetDateTime.now())
.setExpiresOn(OffsetDateTime.now().plusDays(7))
.setPermissions("permissionString"));
client.setAccessPolicy(PublicAccessType.CONTAINER, Collections.singletonList(identifier)).subscribe(
response -> System.out.printf("Set access policy completed%n"),
error -> System.out.printf("Set access policy failed: %s%n", error));
Parameters:
Returns:
setAccessPolicyWithResponse
public Mono
Sets the container's permissions. The permissions indicate whether blobs in a container may be accessed publicly. Note that, for each signed identifier, we will truncate the start and expiry times to the nearest second to ensure the time formatting is compatible with the service. For more information, see the Azure Docs.
Code Samples
BlobSignedIdentifier identifier = new BlobSignedIdentifier()
.setId("name")
.setAccessPolicy(new BlobAccessPolicy()
.setStartsOn(OffsetDateTime.now())
.setExpiresOn(OffsetDateTime.now().plusDays(7))
.setPermissions("permissionString"));
BlobRequestConditions requestConditions = new BlobRequestConditions()
.setLeaseId(leaseId)
.setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
client.setAccessPolicyWithResponse(PublicAccessType.CONTAINER, Collections.singletonList(identifier), requestConditions)
.subscribe(response ->
System.out.printf("Set access policy completed with status %d%n", response.getStatusCode()));
Parameters:
Returns:
setMetadata
public Mono
Sets the container's metadata. For more information, see the Azure Docs.
Code Samples
Map<String, String> metadata = Collections.singletonMap("metadata", "value");
client.setMetadata(metadata).subscribe(
response -> System.out.printf("Set metadata completed%n"),
error -> System.out.printf("Set metadata failed: %s%n", error));
Parameters:
Returns:
setMetadataWithResponse
public Mono
Sets the container's metadata. For more information, see the Azure Docs.
Code Samples
Map<String, String> metadata = Collections.singletonMap("metadata", "value");
BlobRequestConditions requestConditions = new BlobRequestConditions()
.setLeaseId(leaseId)
.setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
client.setMetadataWithResponse(metadata, requestConditions).subscribe(response ->
System.out.printf("Set metadata completed with status %d%n", response.getStatusCode()));
Parameters:
Returns: