Compartir a través de


BlobContainerAsyncClient Class

  • java.lang.Object
    • com.azure.storage.blob.BlobContainerAsyncClient

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

Modifier and Type Method and Description
Mono<Void> create()

Creates a new container within a storage account.

Mono<Boolean> createIfNotExists()

Creates a new container within a storage account if it does not exist.

Mono<Response<Boolean>> createIfNotExistsWithResponse(BlobContainerCreateOptions options)

Creates a new container within a storage account if it does not exist.

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<Boolean> deleteIfExists()

Marks the specified container for deletion if it exists.

Mono<Response<Boolean>> deleteIfExistsWithResponse(BlobRequestConditions requestConditions)

Marks the specified container for deletion if it exists.

Mono<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<Response<Boolean>> existsWithResponse()

Gets if the container this client represents exists in the cloud.

PagedFlux<TaggedBlobItem> findBlobsByTags(FindBlobsOptions options)

Returns a reactive Publisher emitting the blobs in this container whose tags match the query expression.

PagedFlux<TaggedBlobItem> findBlobsByTags(String query)

Returns a reactive Publisher emitting the blobs in this container whose tags match the query expression.

String generateSas(BlobServiceSasSignatureValues blobServiceSasSignatureValues)

Generates a service SAS for the container using the specified BlobServiceSasSignatureValues

String generateSas(BlobServiceSasSignatureValues blobServiceSasSignatureValues, Context context)

Generates a service SAS for the container using the specified BlobServiceSasSignatureValues

String generateSas(BlobServiceSasSignatureValues blobServiceSasSignatureValues, Consumer<String> stringToSignHandler, Context context)

Generates a service SAS for the container using the specified BlobServiceSasSignatureValues

String generateUserDelegationSas(BlobServiceSasSignatureValues blobServiceSasSignatureValues, UserDelegationKey userDelegationKey)

Generates a user delegation SAS for the container using the specified BlobServiceSasSignatureValues.

String generateUserDelegationSas(BlobServiceSasSignatureValues blobServiceSasSignatureValues, UserDelegationKey userDelegationKey, String accountName, Context context)

Generates a user delegation SAS for the container using the specified BlobServiceSasSignatureValues.

String generateUserDelegationSas(BlobServiceSasSignatureValues blobServiceSasSignatureValues, UserDelegationKey userDelegationKey, String accountName, Consumer<String> stringToSignHandler, Context context)

Generates a user delegation SAS for the container using the specified BlobServiceSasSignatureValues.

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.

String getAccountUrl()

Get the url of the storage account.

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.

BlobAsyncClient getBlobVersionAsyncClient(String blobName, String versionId)

Creates a new BlobAsyncClient object by concatenating blobName to the end of ContainerAsyncClient's URL.

CpkInfo getCustomerProvidedKey()

Gets the CpkInfo associated with this client that will be passed to BlobAsyncClient when getBlobAsyncClient(String blobName) is called.

String getEncryptionScope()

Gets the EncryptionScope used to encrypt this blob's content on the server.

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.

BlobServiceAsyncClient getServiceAsyncClient()

Get an async client pointing to the account.

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> listBlobs(ListBlobsOptions options, String continuationToken)

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 requestConditions)

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 requestConditions)

Sets the container's metadata.

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 create()

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:

A reactive response signalling completion.

createIfNotExists

public Mono createIfNotExists()

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:

A reactive response signaling completion. true indicates a new container was created, true indicates a container already existed at this location.

createIfNotExistsWithResponse

public Mono> createIfNotExistsWithResponse(BlobContainerCreateOptions options)

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:

A reactive response signaling completion. If Response<T>'s status code is 201, a new container was successfully created. If status code is 409, a container already existed at this location.

createWithResponse

public Mono> createWithResponse(Map metadata, PublicAccessType accessType)

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:

metadata - Metadata to associate with the container. If there is leading or trailing whitespace in any metadata key or value, it must be removed or encoded.
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.

Returns:

A reactive response signalling completion.

delete

public Mono delete()

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:

A reactive response signalling completion.

deleteIfExists

public Mono deleteIfExists()

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:

A reactive response signaling completion. true indicates the container was deleted, false indicates the container does not exist.

deleteIfExistsWithResponse

public Mono> deleteIfExistsWithResponse(BlobRequestConditions requestConditions)

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:

requestConditions - BlobRequestConditions

Returns:

A reactive response signaling completion. If Response<T>'s status code is 202, the container was successfully deleted. If status code is 404, the container does not exist.

deleteWithResponse

public Mono> deleteWithResponse(BlobRequestConditions requestConditions)

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:

requestConditions - BlobRequestConditions

Returns:

A reactive response signalling completion.

exists

public Mono exists()

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:

true if the container exists, false if it doesn't

existsWithResponse

public Mono> existsWithResponse()

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:

true if the container exists, false if it doesn't

findBlobsByTags

public PagedFlux findBlobsByTags(FindBlobsOptions options)

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:

options - FindBlobsOptions

Returns:

A reactive response emitting the list of blobs.

findBlobsByTags

public PagedFlux findBlobsByTags(String query)

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:

query - Filters the results to return only blobs whose tags match the specified expression.

Returns:

A reactive response emitting the list of blobs.

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:

blobServiceSasSignatureValues - BlobServiceSasSignatureValues

Returns:

A 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:

blobServiceSasSignatureValues - BlobServiceSasSignatureValues
context - Additional context that is passed through the code when generating a SAS.

Returns:

A String representing the SAS query parameters.

generateSas

public String generateSas(BlobServiceSasSignatureValues blobServiceSasSignatureValues, Consumer stringToSignHandler, 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.

Parameters:

blobServiceSasSignatureValues - BlobServiceSasSignatureValues
stringToSignHandler - For debugging purposes only. Returns the string to sign that was used to generate the signature.
context - Additional context that is passed through the code when generating a SAS.

Returns:

A 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:

blobServiceSasSignatureValues - BlobServiceSasSignatureValues
userDelegationKey - A UserDelegationKey object used to sign the SAS values. See getUserDelegationKey(OffsetDateTime start, OffsetDateTime expiry) for more information on how to get a user delegation key.

Returns:

A 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:

blobServiceSasSignatureValues - BlobServiceSasSignatureValues
userDelegationKey - A UserDelegationKey object used to sign the SAS values. See getUserDelegationKey(OffsetDateTime start, OffsetDateTime expiry) for more information on how to get a user delegation key.
accountName - The account name.
context - Additional context that is passed through the code when generating a SAS.

Returns:

A String representing the SAS query parameters.

generateUserDelegationSas

public String generateUserDelegationSas(BlobServiceSasSignatureValues blobServiceSasSignatureValues, UserDelegationKey userDelegationKey, String accountName, Consumer stringToSignHandler, 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.

Parameters:

blobServiceSasSignatureValues - BlobServiceSasSignatureValues
userDelegationKey - A UserDelegationKey object used to sign the SAS values. See getUserDelegationKey(OffsetDateTime start, OffsetDateTime expiry) for more information on how to get a user delegation key.
accountName - The account name.
stringToSignHandler - For debugging purposes only. Returns the string to sign that was used to generate the signature.
context - Additional context that is passed through the code when generating a SAS.

Returns:

A String representing the SAS query parameters.

getAccessPolicy

public Mono getAccessPolicy()

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:

A reactive response containing the container access policy.

getAccessPolicyWithResponse

public Mono> getAccessPolicyWithResponse(String leaseId)

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:

leaseId - The lease ID the active lease on the container must match.

Returns:

A reactive response containing the container access policy.

getAccountInfo

public Mono getAccountInfo()

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:

A reactive response containing the account info.

getAccountInfoWithResponse

public Mono> getAccountInfoWithResponse()

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:

A reactive response containing the account info.

getAccountName

public String getAccountName()

Get associated account name.

Returns:

account name associated with this storage resource.

getAccountUrl

public String getAccountUrl()

Get the url of the storage account.

Returns:

the URL of the storage account

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:

blobName - A 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:

A new BlobAsyncClient object which references the blob with the specified name in this container.

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:

blobName - A String representing the name of the blob. If the blob name contains special characters, pass in the url encoded version of the blob name.
snapshot - the snapshot identifier for the blob.

Returns:

A new BlobAsyncClient object which references the blob with the specified name in this container.

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:

The name of container.

getBlobContainerUrl

public String getBlobContainerUrl()

Gets the URL of the container represented by this client.

Returns:

the URL.

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:

blobName - A String representing the name of the blob. If the blob name contains special characters, pass in the url encoded version of the blob name.
versionId - the version identifier for the blob, pass null to interact with the latest blob version.

Returns:

A new BlobAsyncClient object which references the blob with the specified name in this container.

getCustomerProvidedKey

public CpkInfo getCustomerProvidedKey()

Gets the CpkInfo associated with this client that will be passed to BlobAsyncClient when getBlobAsyncClient(String blobName) is called.

Returns:

the customer provided key used for encryption.

getEncryptionScope

public String getEncryptionScope()

Gets the EncryptionScope used to encrypt this blob's content on the server.

Returns:

the encryption scope used for encryption.

getHttpPipeline

public HttpPipeline getHttpPipeline()

Gets the HttpPipeline powering this client.

Returns:

The pipeline.

getProperties

public Mono getProperties()

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:

A Mono containing a Response<T> whose value containing the container properties.

getPropertiesWithResponse

public Mono> getPropertiesWithResponse(String leaseId)

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:

leaseId - The lease ID the active lease on the container must match.

Returns:

A reactive response containing the container properties.

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:

the service version the client is using.

listBlobs

public PagedFlux listBlobs()

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:

A reactive response emitting the flattened blobs.

listBlobs

public PagedFlux listBlobs(ListBlobsOptions options)

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:

options - ListBlobsOptions

Returns:

A reactive response emitting the listed blobs, flattened.

listBlobs

public PagedFlux listBlobs(ListBlobsOptions options, String continuationToken)

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:

options - ListBlobsOptions
continuationToken - Identifies the portion of the list to be returned with the next list operation.

Returns:

A reactive response emitting the listed blobs, flattened.

listBlobsByHierarchy

public PagedFlux listBlobsByHierarchy(String directory)

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:

directory - The directory to list blobs underneath

Returns:

A reactive response emitting the prefixes and blobs.

listBlobsByHierarchy

public PagedFlux listBlobsByHierarchy(String delimiter, ListBlobsOptions options)

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:

delimiter - The delimiter for blob hierarchy, "/" for hierarchy based on directories
options - ListBlobsOptions

Returns:

A reactive response emitting the prefixes and blobs.

setAccessPolicy

public Mono setAccessPolicy(PublicAccessType accessType, List identifiers)

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:

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.

Returns:

A reactive response signalling completion.

setAccessPolicyWithResponse

public Mono> setAccessPolicyWithResponse(PublicAccessType accessType, List identifiers, BlobRequestConditions requestConditions)

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:

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 - BlobRequestConditions

Returns:

A reactive response signalling completion.

setMetadata

public Mono setMetadata(Map metadata)

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:

metadata - Metadata to associate with the container. If there is leading or trailing whitespace in any metadata key or value, it must be removed or encoded.

Returns:

A Mono containing a Response<T> whose value contains signalling completion.

setMetadataWithResponse

public Mono> setMetadataWithResponse(Map metadata, BlobRequestConditions requestConditions)

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:

metadata - Metadata to associate with the container. If there is leading or trailing whitespace in any metadata key or value, it must be removed or encoded.
requestConditions - BlobRequestConditions

Returns:

A reactive response signalling completion.

Applies to