public final class BlobContainerAsyncClient extends Object
BlobContainerClientBuilder or via the method
BlobServiceAsyncClient.getBlobContainerAsyncClient(String). 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
BlobContainerAsyncClient.getBlobAsyncClient(String), 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().
| Modifier and Type | Field and Description |
|---|---|
static String |
LOG_CONTAINER_NAME |
static String |
ROOT_CONTAINER_NAME |
static String |
STATIC_WEBSITE_CONTAINER_NAME |
| Modifier and Type | Method and Description |
|---|---|
Mono<Void> |
create()
Creates a new container within a storage account.
|
Mono<com.azure.core.http.rest.Response<Void>> |
createWithResponse(Map<String,String> metadata,
PublicAccessType accessType)
Creates a new container within a storage account.
|
Mono<Void> |
delete()
Marks the specified container for deletion.
|
Mono<com.azure.core.http.rest.Response<Void>> |
deleteWithResponse(BlobRequestConditions requestConditions)
Marks the specified container for deletion.
|
Mono<Boolean> |
exists()
Gets if the container this client represents exists in the cloud.
|
Mono<com.azure.core.http.rest.Response<Boolean>> |
existsWithResponse()
Gets if the container this client represents exists in the cloud.
|
String |
generateSas(BlobServiceSasSignatureValues blobServiceSasSignatureValues)
Generates a service SAS for the container using the specified
BlobServiceSasSignatureValues
Note : The client must be authenticated via StorageSharedKeyCredential |
String |
generateUserDelegationSas(BlobServiceSasSignatureValues blobServiceSasSignatureValues,
UserDelegationKey userDelegationKey)
Generates a user delegation SAS for the container using the specified
BlobServiceSasSignatureValues. |
Mono<BlobContainerAccessPolicies> |
getAccessPolicy()
Returns the container's permissions.
|
Mono<com.azure.core.http.rest.Response<BlobContainerAccessPolicies>> |
getAccessPolicyWithResponse(String leaseId)
Returns the container's permissions.
|
Mono<StorageAccountInfo> |
getAccountInfo()
Returns the sku name and account kind for the account.
|
Mono<com.azure.core.http.rest.Response<StorageAccountInfo>> |
getAccountInfoWithResponse()
Returns the sku name and account kind for the account.
|
String |
getAccountName()
Get associated account name.
|
BlobAsyncClient |
getBlobAsyncClient(String blobName)
Creates a new BlobAsyncClient object by concatenating blobName to the end of ContainerAsyncClient's URL.
|
BlobAsyncClient |
getBlobAsyncClient(String blobName,
String snapshot)
Creates a new BlobAsyncClient object by concatenating blobName to the end of ContainerAsyncClient's URL.
|
String |
getBlobContainerName()
Get the container name.
|
String |
getBlobContainerUrl()
Gets the URL of the container represented by this client.
|
CpkInfo |
getCustomerProvidedKey()
Gets the
CpkInfo associated with this client that will be passed to BlobAsyncClients when getBlobAsyncClient is called. |
com.azure.core.http.HttpPipeline |
getHttpPipeline()
Gets the
HttpPipeline powering this client. |
Mono<BlobContainerProperties> |
getProperties()
Returns the container's metadata and system properties.
|
Mono<com.azure.core.http.rest.Response<BlobContainerProperties>> |
getPropertiesWithResponse(String leaseId)
Returns the container's metadata and system properties.
|
BlobServiceVersion |
getServiceVersion()
Gets the service version the client is using.
|
com.azure.core.http.rest.PagedFlux<BlobItem> |
listBlobs()
Returns a reactive Publisher emitting all the blobs in this container lazily as needed.
|
com.azure.core.http.rest.PagedFlux<BlobItem> |
listBlobs(ListBlobsOptions options)
Returns a reactive Publisher emitting all the blobs in this container lazily as needed.
|
com.azure.core.http.rest.PagedFlux<BlobItem> |
listBlobsByHierarchy(String directory)
Returns a reactive Publisher emitting all the blobs and directories (prefixes) under the given directory
(prefix).
|
com.azure.core.http.rest.PagedFlux<BlobItem> |
listBlobsByHierarchy(String delimiter,
ListBlobsOptions options)
Returns a reactive Publisher emitting all the blobs and prefixes (directories) under the given prefix
(directory).
|
Mono<Void> |
setAccessPolicy(PublicAccessType accessType,
List<BlobSignedIdentifier> identifiers)
Sets the container's permissions.
|
Mono<com.azure.core.http.rest.Response<Void>> |
setAccessPolicyWithResponse(PublicAccessType accessType,
List<BlobSignedIdentifier> identifiers,
BlobRequestConditions requestConditions)
Sets the container's permissions.
|
Mono<Void> |
setMetadata(Map<String,String> metadata)
Sets the container's metadata.
|
Mono<com.azure.core.http.rest.Response<Void>> |
setMetadataWithResponse(Map<String,String> metadata,
BlobRequestConditions requestConditions)
Sets the container's metadata.
|
public static final String ROOT_CONTAINER_NAME
public static final String STATIC_WEBSITE_CONTAINER_NAME
public static final String LOG_CONTAINER_NAME
public BlobAsyncClient getBlobAsyncClient(String blobName)
Code Samples
BlobAsyncClient blobAsyncClient = client.getBlobAsyncClient(blobName);
blobName - A String representing the name of the blob.BlobAsyncClient object which references the blob with the specified name in this container.public BlobAsyncClient getBlobAsyncClient(String blobName, String snapshot)
Code Samples
BlobAsyncClient blobAsyncClient = client.getBlobAsyncClient(blobName, snapshot);
blobName - A String representing the name of the blob.snapshot - the snapshot identifier for the blob.BlobAsyncClient object which references the blob with the specified name in this container.public String getBlobContainerUrl()
public String getBlobContainerName()
Code Samples
StringcontainerName = client.getBlobContainerName();System.out.println("The name of the blob is " + containerName);
public String getAccountName()
public BlobServiceVersion getServiceVersion()
public com.azure.core.http.HttpPipeline getHttpPipeline()
HttpPipeline powering this client.public CpkInfo getCustomerProvidedKey()
CpkInfo associated with this client that will be passed to BlobAsyncClients when getBlobAsyncClient is called.public Mono<Boolean> exists()
Code Samples
client.exists().subscribe(response -> System.out.printf("Exists? %b%n", response));
public Mono<com.azure.core.http.rest.Response<Boolean>> existsWithResponse()
Code Samples
client.existsWithResponse().subscribe(response -> System.out.printf("Exists? %b%n", response.getValue()));
public Mono<Void> create()
Code Samples
client.create().subscribe(
response -> System.out.printf("Create completed%n"),
error -> System.out.printf("Error while creating container %s%n", error));
public Mono<com.azure.core.http.rest.Response<Void>> createWithResponse(Map<String,String> metadata, PublicAccessType accessType)
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()));
metadata - Metadata to associate with the container.accessType - Specifies how the data in this container is available to the public. See the
x-ms-blob-public-access header in the Azure Docs for more information. Pass null for no public access.public Mono<Void> delete()
Code Samples
client.delete().subscribe(
response -> System.out.printf("Delete completed%n"),
error -> System.out.printf("Delete failed: %s%n", error));
public Mono<com.azure.core.http.rest.Response<Void>> deleteWithResponse(BlobRequestConditions requestConditions)
Code Samples
BlobRequestConditionsrequestConditions = newBlobRequestConditions() .setLeaseId(leaseId) .setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3)); client.deleteWithResponse(requestConditions).subscribe(response ->System.out.printf("Delete completed with status %d%n", response.getStatusCode()));
requestConditions - BlobRequestConditionsUnsupportedOperationException - If either MatchConditions.getIfMatch() or
MatchConditions.getIfNoneMatch() is set.public Mono<BlobContainerProperties> getProperties()
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()));
Mono containing a Response whose value containing the
container properties.public Mono<com.azure.core.http.rest.Response<BlobContainerProperties>> getPropertiesWithResponse(String leaseId)
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()));
leaseId - The lease ID the active lease on the container must match.public Mono<Void> setMetadata(Map<String,String> metadata)
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));
metadata - Metadata to associate with the container.Mono containing a Response whose value contains signalling
completion.public Mono<com.azure.core.http.rest.Response<Void>> setMetadataWithResponse(Map<String,String> metadata, BlobRequestConditions requestConditions)
Code Samples
Map<String,String> metadata =Collections.singletonMap("metadata", "value");BlobRequestConditionsrequestConditions = newBlobRequestConditions() .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()));
metadata - Metadata to associate with the container.requestConditions - BlobRequestConditionsUnsupportedOperationException - If one of MatchConditions.getIfMatch(),
MatchConditions.getIfNoneMatch(), or RequestConditions.getIfUnmodifiedSince() is set.public Mono<BlobContainerAccessPolicies> getAccessPolicy()
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());
}
});
public Mono<com.azure.core.http.rest.Response<BlobContainerAccessPolicies>> getAccessPolicyWithResponse(String leaseId)
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());
}
});
leaseId - The lease ID the active lease on the container must match.public Mono<Void> setAccessPolicy(PublicAccessType accessType, List<BlobSignedIdentifier> identifiers)
Code Samples
BlobSignedIdentifieridentifier = newBlobSignedIdentifier() .setId("name") .setAccessPolicy(newBlobAccessPolicy() .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));
accessType - Specifies how the data in this container is available to the public. See the
x-ms-blob-public-access header in the Azure Docs for more information. Pass null for no public access.identifiers - A list of BlobSignedIdentifier objects that specify the permissions for the container.
Please see
here
for more information. Passing null will clear all access policies.public Mono<com.azure.core.http.rest.Response<Void>> setAccessPolicyWithResponse(PublicAccessType accessType, List<BlobSignedIdentifier> identifiers, BlobRequestConditions requestConditions)
Code Samples
BlobSignedIdentifieridentifier = newBlobSignedIdentifier() .setId("name") .setAccessPolicy(newBlobAccessPolicy() .setStartsOn(OffsetDateTime.now()) .setExpiresOn(OffsetDateTime.now().plusDays(7)) .setPermissions("permissionString"));BlobRequestConditionsrequestConditions = newBlobRequestConditions() .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()));
accessType - Specifies how the data in this container is available to the public. See the
x-ms-blob-public-access header in the Azure Docs for more information. Pass null for no public access.identifiers - A list of BlobSignedIdentifier objects that specify the permissions for the container.
Please see
here
for more information. Passing null will clear all access policies.requestConditions - BlobRequestConditionsUnsupportedOperationException - If either MatchConditions.getIfMatch() or
MatchConditions.getIfNoneMatch() is set.public com.azure.core.http.rest.PagedFlux<BlobItem> listBlobs()
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
Code Samples
client.listBlobs().subscribe(blob ->
System.out.printf("Name: %s, Directory? %b%n", blob.getName(), blob.isPrefix()));
public com.azure.core.http.rest.PagedFlux<BlobItem> listBlobs(ListBlobsOptions options)
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
ListBlobsOptionsoptions = newListBlobsOptions() .setPrefix("prefixToMatch") .setDetails(newBlobListDetails() .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()));
options - ListBlobsOptionspublic com.azure.core.http.rest.PagedFlux<BlobItem> listBlobsByHierarchy(String directory)
BlobItem.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:
will return the following results when prefix="foo/":
Code Samples
client.listBlobsByHierarchy("directoryName").subscribe(blob ->
System.out.printf("Name: %s, Directory? %b%n", blob.getName(), blob.isDeleted()));
directory - The directory to list blobs underneathpublic com.azure.core.http.rest.PagedFlux<BlobItem> listBlobsByHierarchy(String delimiter, ListBlobsOptions options)
BlobItem.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:
will return the following results when prefix="foo/":
Code Samples
ListBlobsOptionsoptions = newListBlobsOptions() .setPrefix("directoryName") .setDetails(newBlobListDetails() .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()));
delimiter - The delimiter for blob hierarchy, "/" for hierarchy based on directoriesoptions - ListBlobsOptionspublic Mono<StorageAccountInfo> getAccountInfo()
Code Samples
client.getAccountInfo().subscribe(response ->
System.out.printf("Account Kind: %s, SKU: %s%n",
response.getAccountKind(),
response.getSkuName()));
public Mono<com.azure.core.http.rest.Response<StorageAccountInfo>> getAccountInfoWithResponse()
Code Samples
client.getAccountInfoWithResponse().subscribe(response ->
System.out.printf("Account Kind: %s, SKU: %s%n",
response.getValue().getAccountKind(),
response.getValue().getSkuName()));
public String generateUserDelegationSas(BlobServiceSasSignatureValues blobServiceSasSignatureValues, UserDelegationKey userDelegationKey)
BlobServiceSasSignatureValues.
See BlobServiceSasSignatureValues for more information on how to construct a user delegation SAS.
Code Samples
OffsetDateTimemyExpiryTime =OffsetDateTime.now().plusDays(1);BlobContainerSasPermissionmyPermission = newBlobContainerSasPermission().setReadPermission(true);BlobServiceSasSignatureValuesmyValues = newBlobServiceSasSignatureValues(expiryTime, permission) .setStartTime(OffsetDateTime.now()); client.generateUserDelegationSas(values, userDelegationKey);
blobServiceSasSignatureValues - BlobServiceSasSignatureValuesuserDelegationKey - A UserDelegationKey object used to sign the SAS values.String representing all SAS query parameters.for more information on how to
get a user delegation key.public String generateSas(BlobServiceSasSignatureValues blobServiceSasSignatureValues)
BlobServiceSasSignatureValues
Note : The client must be authenticated via StorageSharedKeyCredential
See BlobServiceSasSignatureValues for more information on how to construct a service SAS.
Code Samples
OffsetDateTimeexpiryTime =OffsetDateTime.now().plusDays(1);BlobContainerSasPermissionpermission = newBlobContainerSasPermission().setReadPermission(true);BlobServiceSasSignatureValuesvalues = newBlobServiceSasSignatureValues(expiryTime, permission) .setStartTime(OffsetDateTime.now()); client.generateSas(values); // Client must be authenticated via StorageSharedKeyCredential
blobServiceSasSignatureValues - BlobServiceSasSignatureValuesString representing all SAS query parameters.Copyright © 2020 Microsoft Corporation. All rights reserved.