public final class BlobServiceAsyncClient extends Object
BlobServiceClientBuilder
. This class does
not hold any state about a particular storage account 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 and containers.
This client contains operations on a blob. Operations on a container are available on BlobContainerAsyncClient
through BlobServiceAsyncClient.getBlobContainerAsyncClient(String)
, and operations on a blob are
available on BlobAsyncClient
.
Please see here 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 | Method and Description |
---|---|
Mono<BlobContainerAsyncClient> |
createBlobContainer(String containerName)
Creates a new container within a storage account.
|
Mono<com.azure.core.http.rest.Response<BlobContainerAsyncClient>> |
createBlobContainerWithResponse(String containerName,
Map<String,String> metadata,
PublicAccessType accessType)
Creates a new container within a storage account.
|
Mono<Void> |
deleteBlobContainer(String containerName)
Deletes the specified container in the storage account.
|
Mono<com.azure.core.http.rest.Response<Void>> |
deleteBlobContainerWithResponse(String containerName)
Deletes the specified container in the storage account.
|
com.azure.core.http.rest.PagedFlux<TaggedBlobItem> |
findBlobsByTags(FindBlobsOptions options)
Returns a reactive Publisher emitting the blobs in this account whose tags match the query expression.
|
com.azure.core.http.rest.PagedFlux<TaggedBlobItem> |
findBlobsByTags(String query)
Returns a reactive Publisher emitting the blobs in this account whose tags match the query expression.
|
String |
generateAccountSas(AccountSasSignatureValues accountSasSignatureValues)
Generates an account SAS for the Azure Storage account using the specified
AccountSasSignatureValues . |
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.
|
String |
getAccountUrl()
Gets the URL of the storage account represented by this client.
|
BlobContainerAsyncClient |
getBlobContainerAsyncClient(String containerName)
Initializes a
BlobContainerAsyncClient object pointing to the specified container. |
com.azure.core.http.HttpPipeline |
getHttpPipeline()
Gets the
HttpPipeline powering this client. |
Mono<BlobServiceProperties> |
getProperties()
Gets the properties of a storage account’s Blob service.
|
Mono<com.azure.core.http.rest.Response<BlobServiceProperties>> |
getPropertiesWithResponse()
Gets the properties of a storage account’s Blob service.
|
BlobServiceVersion |
getServiceVersion()
Gets the service version the client is using.
|
Mono<BlobServiceStatistics> |
getStatistics()
Retrieves statistics related to replication for the Blob service.
|
Mono<com.azure.core.http.rest.Response<BlobServiceStatistics>> |
getStatisticsWithResponse()
Retrieves statistics related to replication for the Blob service.
|
Mono<UserDelegationKey> |
getUserDelegationKey(OffsetDateTime start,
OffsetDateTime expiry)
Gets a user delegation key for use with this account's blob storage.
|
Mono<com.azure.core.http.rest.Response<UserDelegationKey>> |
getUserDelegationKeyWithResponse(OffsetDateTime start,
OffsetDateTime expiry)
Gets a user delegation key for use with this account's blob storage.
|
com.azure.core.http.rest.PagedFlux<BlobContainerItem> |
listBlobContainers()
Returns a reactive Publisher emitting all the containers in this account lazily as needed.
|
com.azure.core.http.rest.PagedFlux<BlobContainerItem> |
listBlobContainers(ListBlobContainersOptions options)
Returns a reactive Publisher emitting all the containers in this account lazily as needed.
|
Mono<Void> |
setProperties(BlobServiceProperties properties)
Sets properties for a storage account's Blob service endpoint.
|
Mono<com.azure.core.http.rest.Response<Void>> |
setPropertiesWithResponse(BlobServiceProperties properties)
Sets properties for a storage account's Blob service endpoint.
|
Mono<BlobContainerAsyncClient> |
undeleteBlobContainer(String deletedContainerName,
String deletedContainerVersion)
Restores a previously deleted container.
|
Mono<com.azure.core.http.rest.Response<BlobContainerAsyncClient>> |
undeleteBlobContainerWithResponse(UndeleteBlobContainerOptions options)
Restores a previously deleted container.
|
public BlobContainerAsyncClient getBlobContainerAsyncClient(String containerName)
BlobContainerAsyncClient
object pointing to the specified container. This method does not
create a container. It simply constructs the URL to the container and offers access to methods relevant to
containers.
Code Samples
BlobContainerAsyncClient blobContainerAsyncClient = client.getBlobContainerAsyncClient("containerName");
containerName
- The name of the container to point to. A value of null or empty string will be interpreted
as pointing to the root container and will be replaced by "$root".BlobContainerAsyncClient
object pointing to the specified containerpublic com.azure.core.http.HttpPipeline getHttpPipeline()
HttpPipeline
powering this client.public BlobServiceVersion getServiceVersion()
public Mono<BlobContainerAsyncClient> createBlobContainer(String containerName)
Code Samples
BlobContainerAsyncClient blobContainerAsyncClient = client.createBlobContainer("containerName").block();
containerName
- Name of the container to createMono
containing a BlobContainerAsyncClient
used to interact with the container created.public Mono<com.azure.core.http.rest.Response<BlobContainerAsyncClient>> createBlobContainerWithResponse(String containerName, Map<String,String> metadata, PublicAccessType accessType)
Code Samples
Map<String, String> metadata = Collections.singletonMap("metadata", "value"); BlobContainerAsyncClient containerClient = client .createBlobContainerWithResponse("containerName", metadata, PublicAccessType.CONTAINER).block().getValue();
containerName
- Name of the container to createmetadata
- Metadata to associate with the containeraccessType
- 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.Mono
containing a Response
whose value
contains a BlobContainerAsyncClient
used to interact with the container created.public Mono<Void> deleteBlobContainer(String containerName)
Code Samples
client.deleteBlobContainer("containerName").subscribe( response -> System.out.printf("Delete container completed%n"), error -> System.out.printf("Delete container failed: %s%n", error));
containerName
- Name of the container to deleteMono
containing containing status code and HTTP headerspublic Mono<com.azure.core.http.rest.Response<Void>> deleteBlobContainerWithResponse(String containerName)
Code Samples
Context context = new Context("Key", "Value"); client.deleteBlobContainerWithResponse("containerName").subscribe(response -> System.out.printf("Delete container completed with status %d%n", response.getStatusCode()));
containerName
- Name of the container to deleteMono
containing containing status code and HTTP headerspublic String getAccountUrl()
public com.azure.core.http.rest.PagedFlux<BlobContainerItem> listBlobContainers()
Code Samples
client.listBlobContainers().subscribe(container -> System.out.printf("Name: %s%n", container.getName()));
public com.azure.core.http.rest.PagedFlux<BlobContainerItem> listBlobContainers(ListBlobContainersOptions options)
Code Samples
ListBlobContainersOptions options = new ListBlobContainersOptions() .setPrefix("containerNamePrefixToMatch") .setDetails(new BlobContainerListDetails().setRetrieveMetadata(true)); client.listBlobContainers(options).subscribe(container -> System.out.printf("Name: %s%n", container.getName()));
options
- A ListBlobContainersOptions
which specifies what data should be returned by the service.public com.azure.core.http.rest.PagedFlux<TaggedBlobItem> findBlobsByTags(String query)
Code Samples
client.findBlobsByTags("where=tag=value").subscribe(blob -> System.out.printf("Name: %s%n", blob.getName()));
query
- Filters the results to return only blobs whose tags match the specified expression.public com.azure.core.http.rest.PagedFlux<TaggedBlobItem> findBlobsByTags(FindBlobsOptions options)
Code Samples
client.findBlobsByTags(new FindBlobsOptions("where=tag=value").setMaxResultsPerPage(10)) .subscribe(blob -> System.out.printf("Name: %s%n", blob.getName()));
options
- FindBlobsOptions
public Mono<BlobServiceProperties> getProperties()
Code Samples
client.getProperties().subscribe(response -> System.out.printf("Hour metrics enabled: %b, Minute metrics enabled: %b%n", response.getHourMetrics().isEnabled(), response.getMinuteMetrics().isEnabled()));
public Mono<com.azure.core.http.rest.Response<BlobServiceProperties>> getPropertiesWithResponse()
Code Samples
client.getPropertiesWithResponse().subscribe(response -> System.out.printf("Hour metrics enabled: %b, Minute metrics enabled: %b%n", response.getValue().getHourMetrics().isEnabled(), response.getValue().getMinuteMetrics().isEnabled()));
Mono
containing a Response
whose value
contains the storage
account properties.public Mono<Void> setProperties(BlobServiceProperties properties)
This method checks to ensure the properties being sent follow the specifications indicated in the Azure Docs. If CORS policies are set, CORS parameters that are not set default to the empty string.
Code Samples
BlobRetentionPolicy loggingRetentionPolicy = new BlobRetentionPolicy().setEnabled(true).setDays(3); BlobRetentionPolicy metricsRetentionPolicy = new BlobRetentionPolicy().setEnabled(true).setDays(1); BlobServiceProperties properties = new BlobServiceProperties() .setLogging(new BlobAnalyticsLogging() .setWrite(true) .setDelete(true) .setRetentionPolicy(loggingRetentionPolicy)) .setHourMetrics(new BlobMetrics() .setEnabled(true) .setRetentionPolicy(metricsRetentionPolicy)) .setMinuteMetrics(new BlobMetrics() .setEnabled(true) .setRetentionPolicy(metricsRetentionPolicy)); client.setProperties(properties).subscribe( response -> System.out.printf("Setting properties completed%n"), error -> System.out.printf("Setting properties failed: %s%n", error));
properties
- Configures the service.Mono
containing the storage account properties.public Mono<com.azure.core.http.rest.Response<Void>> setPropertiesWithResponse(BlobServiceProperties properties)
This method checks to ensure the properties being sent follow the specifications indicated in the Azure Docs. If CORS policies are set, CORS parameters that are not set default to the empty string.
Code Samples
BlobRetentionPolicy loggingRetentionPolicy = new BlobRetentionPolicy().setEnabled(true).setDays(3); BlobRetentionPolicy metricsRetentionPolicy = new BlobRetentionPolicy().setEnabled(true).setDays(1); BlobServiceProperties properties = new BlobServiceProperties() .setLogging(new BlobAnalyticsLogging() .setWrite(true) .setDelete(true) .setRetentionPolicy(loggingRetentionPolicy)) .setHourMetrics(new BlobMetrics() .setEnabled(true) .setRetentionPolicy(metricsRetentionPolicy)) .setMinuteMetrics(new BlobMetrics() .setEnabled(true) .setRetentionPolicy(metricsRetentionPolicy)); client.setPropertiesWithResponse(properties).subscribe(response -> System.out.printf("Setting properties completed with status %d%n", response.getStatusCode()));
properties
- Configures the service.Mono
containing the storage account properties.public Mono<UserDelegationKey> getUserDelegationKey(OffsetDateTime start, OffsetDateTime expiry)
TokenCredential
in this object's HttpPipeline
.
Code Samples
client.getUserDelegationKey(delegationKeyStartTime, delegationKeyExpiryTime).subscribe(response -> System.out.printf("User delegation key: %s%n", response.getValue()));
start
- Start time for the key's validity. Null indicates immediate start.expiry
- Expiration of the key's validity.Mono
containing the user delegation key.IllegalArgumentException
- If start
isn't null and is after expiry
.NullPointerException
- If expiry
is null.public Mono<com.azure.core.http.rest.Response<UserDelegationKey>> getUserDelegationKeyWithResponse(OffsetDateTime start, OffsetDateTime expiry)
TokenCredential
in this object's HttpPipeline
.
Code Samples
client.getUserDelegationKeyWithResponse(delegationKeyStartTime, delegationKeyExpiryTime).subscribe(response -> System.out.printf("User delegation key: %s%n", response.getValue().getValue()));
start
- Start time for the key's validity. Null indicates immediate start.expiry
- Expiration of the key's validity.Mono
containing a Response
whose value
containing the user
delegation key.IllegalArgumentException
- If start
isn't null and is after expiry
.NullPointerException
- If expiry
is null.public Mono<BlobServiceStatistics> getStatistics()
Code Samples
client.getStatistics().subscribe(response -> System.out.printf("Geo-replication status: %s%n", response.getGeoReplication().getStatus()));
Mono
containing the storage account statistics.public Mono<com.azure.core.http.rest.Response<BlobServiceStatistics>> getStatisticsWithResponse()
Code Samples
client.getStatisticsWithResponse().subscribe(response -> System.out.printf("Geo-replication status: %s%n", response.getValue().getGeoReplication().getStatus()));
Mono
containing a Response
whose value
containing the
storage account statistics.public Mono<StorageAccountInfo> getAccountInfo()
Code Samples
client.getAccountInfo().subscribe(response -> System.out.printf("Account kind: %s, SKU: %s%n", response.getAccountKind(), response.getSkuName()));
Mono
containing containing the storage account info.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()));
Mono
containing a Response
whose value
the storage account
info.public String getAccountName()
public String generateAccountSas(AccountSasSignatureValues accountSasSignatureValues)
AccountSasSignatureValues
.
Note : The client must be authenticated via StorageSharedKeyCredential
See AccountSasSignatureValues
for more information on how to construct an account SAS.
The snippet below generates a SAS that lasts for two days and gives the user read and list access to blob containers and file shares.
AccountSasPermission permissions = new AccountSasPermission() .setListPermission(true) .setReadPermission(true); AccountSasResourceType resourceTypes = new AccountSasResourceType().setContainer(true); AccountSasService services = new AccountSasService().setBlobAccess(true).setFileAccess(true); OffsetDateTime expiryTime = OffsetDateTime.now().plus(Duration.ofDays(2)); AccountSasSignatureValues sasValues = new AccountSasSignatureValues(expiryTime, permissions, services, resourceTypes); // Client must be authenticated via StorageSharedKeyCredential String sas = client.generateAccountSas(sasValues);
accountSasSignatureValues
- AccountSasSignatureValues
String
representing all SAS query parameters.public Mono<BlobContainerAsyncClient> undeleteBlobContainer(String deletedContainerName, String deletedContainerVersion)
deletedContainerName
already exists, this call will result in a 409 (conflict).
This API is only functional if Container Soft Delete is enabled
for the storage account associated with the container.
Code Samples
ListBlobContainersOptions listBlobContainersOptions = new ListBlobContainersOptions(); listBlobContainersOptions.getDetails().setRetrieveDeleted(true); client.listBlobContainers(listBlobContainersOptions).flatMap( deletedContainer -> { Mono<BlobContainerAsyncClient> blobContainerClient = client.undeleteBlobContainer( deletedContainer.getName(), deletedContainer.getVersion()); return blobContainerClient; } ).then().block();
deletedContainerName
- The name of the previously deleted container.deletedContainerVersion
- The version of the previously deleted container.Mono
containing a BlobContainerAsyncClient
used
to interact with the restored container.public Mono<com.azure.core.http.rest.Response<BlobContainerAsyncClient>> undeleteBlobContainerWithResponse(UndeleteBlobContainerOptions options)
destinationContainerName
if provided in options
.
Otherwise deletedContainerName
is used as destination container name.
If the container associated with provided destinationContainerName
already exists, this call will result in a 409 (conflict).
This API is only functional if Container Soft Delete is enabled
for the storage account associated with the container.
Code Samples
ListBlobContainersOptions listBlobContainersOptions = new ListBlobContainersOptions(); listBlobContainersOptions.getDetails().setRetrieveDeleted(true); client.listBlobContainers(listBlobContainersOptions).flatMap( deletedContainer -> { Mono<BlobContainerAsyncClient> blobContainerClient = client.undeleteBlobContainerWithResponse( new UndeleteBlobContainerOptions(deletedContainer.getName(), deletedContainer.getVersion()) .setDestinationContainerName(deletedContainer.getName() + "V2")) .map(Response::getValue); return blobContainerClient; } ).then().block();
options
- UndeleteBlobContainerOptions
.Mono
containing a Response
whose value
contains a BlobContainerAsyncClient
used to interact with the restored container.Copyright © 2020 Microsoft Corporation. All rights reserved.