你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
BlobServiceAsyncClient Class
- java.
lang. Object - com.
azure. storage. blob. BlobServiceAsyncClient
- com.
public final class BlobServiceAsyncClient
Client to a storage account. It may only be instantiated through a 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 getBlobContainerAsyncClient(String containerName), and operations on a blob are available on BlobAsyncClient.
Please see 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().
Method Summary
Methods inherited from java.lang.Object
Method Details
createBlobContainer
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
BlobContainerAsyncClient blobContainerAsyncClient =
client.createBlobContainer("containerName").block();
Parameters:
Returns:
createBlobContainerIfNotExists
public Mono
Creates a new container within a storage account if it does not exist. For more information, see the Azure Docs.
Code Samples
BlobContainerAsyncClient blobContainerAsyncClient =
client.createBlobContainerIfNotExists("containerName").block();
Parameters:
Returns:
createBlobContainerIfNotExistsWithResponse
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.createBlobContainerIfNotExistsWithResponse("containerName", options).subscribe(response -> {
if (response.getStatusCode() == 409) {
System.out.println("Already exists.");
} else {
System.out.println("successfully created.");
}
});
Parameters:
Returns:
createBlobContainerWithResponse
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");
BlobContainerAsyncClient containerClient = client
.createBlobContainerWithResponse("containerName", metadata, PublicAccessType.CONTAINER).block().getValue();
Parameters:
Returns:
deleteBlobContainer
public Mono
Deletes the specified container in the storage account. If the container doesn't exist the operation fails. For more information see the Azure Docs.
Code Samples
client.deleteBlobContainer("containerName").subscribe(
response -> System.out.printf("Delete container completed%n"),
error -> System.out.printf("Delete container failed: %s%n", error));
Parameters:
Returns:
deleteBlobContainerIfExists
public Mono
Deletes the specified container in the storage account if it exists. For more information see the Azure Docs.
Code Samples
client.deleteBlobContainerIfExists("containerName").subscribe(deleted -> {
if (deleted) {
System.out.println("Successfully deleted.");
} else {
System.out.println("Does not exist.");
}
});
Parameters:
Returns:
true
indicates that the container was deleted.
false
indicates the container does not exist at this location.deleteBlobContainerIfExistsWithResponse
public Mono
Deletes the specified container in the storage account if it exists. For more information see the Azure Docs.
Code Samples
Context context = new Context("Key", "Value");
client.deleteBlobContainerIfExistsWithResponse("containerName").subscribe(response -> {
if (response.getStatusCode() == 404) {
System.out.println("Does not exist.");
} else {
System.out.println("successfully deleted.");
}
});
Parameters:
Returns:
deleteBlobContainerWithResponse
public Mono
Deletes the specified container in the storage account. If the container doesn't exist the operation fails. For more information see the Azure Docs.
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()));
Parameters:
Returns:
findBlobsByTags
public PagedFlux
Returns a reactive Publisher emitting the blobs in this account 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 account 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:
generateAccountSas
public String generateAccountSas(AccountSasSignatureValues accountSasSignatureValues)
Generates an account SAS for the Azure Storage account using the specified 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);
Parameters:
Returns:
String
representing the SAS query parameters.generateAccountSas
public String generateAccountSas(AccountSasSignatureValues accountSasSignatureValues, Context context)
Generates an account SAS for the Azure Storage account using the specified 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, new Context("key", "value"));
Parameters:
Returns:
String
representing the SAS query parameters.generateAccountSas
public String generateAccountSas(AccountSasSignatureValues accountSasSignatureValues, Consumer
Generates an account SAS for the Azure Storage account using the specified AccountSasSignatureValues.
Note : The client must be authenticated via StorageSharedKeyCredential
See AccountSasSignatureValues for more information on how to construct an account SAS.
Parameters:
Returns:
String
representing the SAS query parameters.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()
Gets the URL of the storage account represented by this client.
Returns:
getBlobContainerAsyncClient
public BlobContainerAsyncClient getBlobContainerAsyncClient(String containerName)
Initializes a 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");
Parameters:
Returns:
getHttpPipeline
public HttpPipeline getHttpPipeline()
Gets the HttpPipeline powering this client.
Returns:
getProperties
public Mono
Gets the properties of a storage account\u2019s Blob service. For more information, see the Azure Docs.
Code Samples
client.getProperties().subscribe(response ->
System.out.printf("Hour metrics enabled: %b, Minute metrics enabled: %b%n",
response.getHourMetrics().isEnabled(),
response.getMinuteMetrics().isEnabled()));
Returns:
getPropertiesWithResponse
public Mono
Gets the properties of a storage account\u2019s Blob service. For more information, see the Azure Docs.
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()));
Returns:
getServiceVersion
public BlobServiceVersion getServiceVersion()
Gets the service version the client is using.
Returns:
getStatistics
public Mono
Retrieves statistics related to replication for the Blob service. It is only available on the secondary location endpoint when read-access geo-redundant replication is enabled for the storage account. For more information, see the Azure Docs.
Code Samples
client.getStatistics().subscribe(response ->
System.out.printf("Geo-replication status: %s%n", response.getGeoReplication().getStatus()));
Returns:
getStatisticsWithResponse
public Mono
Retrieves statistics related to replication for the Blob service. It is only available on the secondary location endpoint when read-access geo-redundant replication is enabled for the storage account. For more information, see the Azure Docs.
Code Samples
client.getStatisticsWithResponse().subscribe(response ->
System.out.printf("Geo-replication status: %s%n", response.getValue().getGeoReplication().getStatus()));
Returns:
getUserDelegationKey
public Mono
Gets a user delegation key for use with this account's blob storage. Note: This method call is only valid when using TokenCredential in this object's HttpPipeline.
Code Samples
client.getUserDelegationKey(delegationKeyStartTime, delegationKeyExpiryTime).subscribe(response ->
System.out.printf("User delegation key: %s%n", response.getValue()));
Parameters:
Returns:
getUserDelegationKeyWithResponse
public Mono
Gets a user delegation key for use with this account's blob storage. Note: This method call is only valid when using 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()));
Parameters:
Returns:
listBlobContainers
public PagedFlux
Returns a reactive Publisher emitting all the containers in this account lazily as needed. For more information, see the Azure Docs.
Code Samples
client.listBlobContainers().subscribe(container -> System.out.printf("Name: %s%n", container.getName()));
Returns:
listBlobContainers
public PagedFlux
Returns a reactive Publisher emitting all the containers in this account lazily as needed. For more information, see the Azure Docs.
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()));
Parameters:
Returns:
setProperties
public Mono
Sets properties for a storage account's Blob service endpoint. For more information, see the Azure Docs. Note that setting the default service version has no effect when using this client because this client explicitly sets the version header on each request, overriding the default.
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));
Parameters:
Returns:
setPropertiesWithResponse
public Mono
Sets properties for a storage account's Blob service endpoint. For more information, see the Azure Docs. Note that setting the default service version has no effect when using this client because this client explicitly sets the version header on each request, overriding the default.
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()));
Parameters:
Returns:
undeleteBlobContainer
public Mono
Restores a previously deleted container. If the container associated with provided 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();
Parameters:
Returns:
undeleteBlobContainerWithResponse
public Mono
Restores a previously deleted container. The restored container will be renamed to the 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()))
.map(Response::getValue);
return blobContainerClient;
}
).then().block();
Parameters:
Returns: