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<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<Response<Void>> |
deleteWithResponse(BlobRequestConditions accessConditions)
Marks the specified container for deletion.
|
Mono<Boolean> |
exists()
Gets if the container this client represents exists in the cloud.
|
Mono<Response<Boolean>> |
existsWithResponse()
Gets if the container this client represents exists in the cloud.
|
Mono<BlobContainerAccessPolicies> |
getAccessPolicy()
Returns the container's permissions.
|
Mono<Response<BlobContainerAccessPolicies>> |
getAccessPolicyWithResponse(String leaseId)
Returns the container's permissions.
|
Mono<StorageAccountInfo> |
getAccountInfo()
Returns the sku name and account kind for the account.
|
Mono<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. |
HttpPipeline |
getHttpPipeline()
Gets the
HttpPipeline powering this client. |
Mono<BlobContainerProperties> |
getProperties()
Returns the container's metadata and system properties.
|
Mono<Response<BlobContainerProperties>> |
getPropertiesWithResponse(String leaseId)
Returns the container's metadata and system properties.
|
BlobServiceVersion |
getServiceVersion()
Gets the service version the client is using.
|
PagedFlux<BlobItem> |
listBlobs()
Returns a reactive Publisher emitting all the blobs in this container lazily as needed.
|
PagedFlux<BlobItem> |
listBlobs(ListBlobsOptions options)
Returns a reactive Publisher emitting all the blobs in this container lazily as needed.
|
PagedFlux<BlobItem> |
listBlobsByHierarchy(String directory)
Returns a reactive Publisher emitting all the blobs and directories (prefixes) under the given directory
(prefix).
|
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<Response<Void>> |
setAccessPolicyWithResponse(PublicAccessType accessType,
List<BlobSignedIdentifier> identifiers,
BlobRequestConditions accessConditions)
Sets the container's permissions.
|
Mono<Void> |
setMetadata(Map<String,String> metadata)
Sets the container's metadata.
|
Mono<Response<Void>> |
setMetadataWithResponse(Map<String,String> metadata,
BlobRequestConditions accessConditions)
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
String
containerName = client.getBlobContainerName();System
.out.println("The name of the blob is " + containerName);
public String getAccountName()
public BlobServiceVersion getServiceVersion()
public 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<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<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<Response<Void>> deleteWithResponse(BlobRequestConditions accessConditions)
Code Samples
BlobRequestConditions
accessConditions = newBlobRequestConditions
() .setLeaseId(leaseId) .setIfUnmodifiedSince(OffsetDateTime
.now().minusDays(3)); client.deleteWithResponse(accessConditions).subscribe(response ->System
.out.printf("Delete completed with status %d%n", response.getStatusCode()));
accessConditions
- BlobRequestConditions
UnsupportedOperationException
- 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()));
public Mono<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));
public Mono<Response<Void>> setMetadataWithResponse(Map<String,String> metadata, BlobRequestConditions accessConditions)
Code Samples
Map
<String
,String
> metadata =Collections
.singletonMap("metadata", "value");BlobRequestConditions
accessConditions = newBlobRequestConditions
() .setLeaseId(leaseId) .setIfUnmodifiedSince(OffsetDateTime
.now().minusDays(3)); client.setMetadataWithResponse(metadata, accessConditions).subscribe(response ->System
.out.printf("Set metadata completed with status %d%n", response.getStatusCode()));
metadata
- Metadata to associate with the container.accessConditions
- BlobRequestConditions
UnsupportedOperationException
- 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<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
BlobSignedIdentifier
identifier = 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<Response<Void>> setAccessPolicyWithResponse(PublicAccessType accessType, List<BlobSignedIdentifier> identifiers, BlobRequestConditions accessConditions)
Code Samples
BlobSignedIdentifier
identifier = newBlobSignedIdentifier
() .setId("name") .setAccessPolicy(newBlobAccessPolicy
() .setStartsOn(OffsetDateTime
.now()) .setExpiresOn(OffsetDateTime
.now().plusDays(7)) .setPermissions("permissionString"));BlobRequestConditions
accessConditions = newBlobRequestConditions
() .setLeaseId(leaseId) .setIfUnmodifiedSince(OffsetDateTime
.now().minusDays(3)); client.setAccessPolicyWithResponse(PublicAccessType
.CONTAINER,Collections
.singletonList(identifier), accessConditions) .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.accessConditions
- BlobRequestConditions
UnsupportedOperationException
- If either MatchConditions.getIfMatch()
or
MatchConditions.getIfNoneMatch()
is set.public 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 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
ListBlobsOptions
options = 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
- ListBlobsOptions
public 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 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
ListBlobsOptions
options = 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
- ListBlobsOptions
public Mono<StorageAccountInfo> getAccountInfo()
Code Samples
client.getAccountInfo().subscribe(response ->
System
.out.printf("Account Kind: %s, SKU: %s%n",
response.getAccountKind(),
response.getSkuName()));
public Mono<Response<StorageAccountInfo>> getAccountInfoWithResponse()
Code Samples
client.getAccountInfoWithResponse().subscribe(response ->
System
.out.printf("Account Kind: %s, SKU: %s%n",
response.getValue().getAccountKind(),
response.getValue().getSkuName()));
Copyright © 2019 Microsoft Corporation. All rights reserved.