public final class BlobServiceClient 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 BlobContainerClient
through BlobServiceClient.getBlobContainerClient(String)
, and operations on a blob are available on BlobClient
.
Please see here for more information on containers.
Modifier and Type | Method and Description |
---|---|
BlobContainerClient |
createBlobContainer(String containerName)
Creates a new container within a storage account.
|
Response<BlobContainerClient> |
createBlobContainerWithResponse(String containerName,
Map<String,String> metadata,
PublicAccessType accessType,
Context context)
Creates a new container within a storage account.
|
void |
deleteBlobContainer(String containerName)
Deletes the specified container in the storage account.
|
Response<Void> |
deleteBlobContainerWithResponse(String containerName,
Context context)
Deletes the specified container in the storage account.
|
StorageAccountInfo |
getAccountInfo()
Returns the sku name and account kind for the account.
|
Response<StorageAccountInfo> |
getAccountInfoWithResponse(Duration timeout,
Context context)
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.
|
BlobContainerClient |
getBlobContainerClient(String containerName)
Initializes a
BlobContainerClient object pointing to the specified container. |
HttpPipeline |
getHttpPipeline()
Gets the
HttpPipeline powering this client. |
BlobServiceProperties |
getProperties()
Gets the properties of a storage account’s Blob service.
|
Response<BlobServiceProperties> |
getPropertiesWithResponse(Duration timeout,
Context context)
Gets the properties of a storage account’s Blob service.
|
BlobServiceVersion |
getServiceVersion()
Gets the service version the client is using.
|
BlobServiceStatistics |
getStatistics()
Retrieves statistics related to replication for the Blob service.
|
Response<BlobServiceStatistics> |
getStatisticsWithResponse(Duration timeout,
Context context)
Retrieves statistics related to replication for the Blob service.
|
UserDelegationKey |
getUserDelegationKey(OffsetDateTime start,
OffsetDateTime expiry)
Gets a user delegation key for use with this account's blob storage.
|
Response<UserDelegationKey> |
getUserDelegationKeyWithResponse(OffsetDateTime start,
OffsetDateTime expiry,
Duration timeout,
Context context)
Gets a user delegation key for use with this account's blob storage.
|
PagedIterable<BlobContainerItem> |
listBlobContainers()
Returns a lazy loaded list of containers in this account.
|
PagedIterable<BlobContainerItem> |
listBlobContainers(ListBlobContainersOptions options,
Duration timeout)
Returns a lazy loaded list of containers in this account.
|
void |
setProperties(BlobServiceProperties properties)
Sets properties for a storage account's Blob service endpoint.
|
Response<Void> |
setPropertiesWithResponse(BlobServiceProperties properties,
Duration timeout,
Context context)
Sets properties for a storage account's Blob service endpoint.
|
public BlobContainerClient getBlobContainerClient(String containerName)
BlobContainerClient
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
BlobContainerClient
blobContainerClient = client.getBlobContainerClient("containerName");
containerName
- The name of the container to point to.BlobContainerClient
object pointing to the specified containerpublic HttpPipeline getHttpPipeline()
HttpPipeline
powering this client.public BlobServiceVersion getServiceVersion()
public BlobContainerClient createBlobContainer(String containerName)
Code Samples
BlobContainerClient
blobContainerClient = client.createBlobContainer("containerName");
containerName
- Name of the container to createBlobContainerClient
used to interact with the container created.public Response<BlobContainerClient> createBlobContainerWithResponse(String containerName, Map<String,String> metadata, PublicAccessType accessType, Context context)
Code Samples
Map
<String
,String
> metadata =Collections
.singletonMap("metadata", "value");Context
context = newContext
("Key", "Value");BlobContainerClient
blobContainerClient = client.createBlobContainerWithResponse( "containerName", metadata,PublicAccessType
.CONTAINER, context).getValue();
containerName
- Name of the container to createmetadata
- 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.context
- Additional context that is passed through the Http pipeline during the service call.Response
whose value
contains the BlobContainerClient
used
to interact with the container created.public void deleteBlobContainer(String containerName)
Code Samples
try { client.deleteBlobContainer("container Name");System
.out.printf("Delete container completed with status %n"); } catch (UnsupportedOperationException
error) {System
.out.printf("Delete container failed: %s%n", error); }
containerName
- Name of the container to deletepublic Response<Void> deleteBlobContainerWithResponse(String containerName, Context context)
containerName
- Name of the container to deletecontext
- Additional context that is passed through the Http pipeline during the service call.public String getAccountUrl()
public PagedIterable<BlobContainerItem> listBlobContainers()
PagedIterable
can be consumed
while new items are automatically retrieved as needed. For more information, see the Azure Docs.
Code Samples
client.listBlobContainers().forEach(container -> System
.out.printf("Name: %s%n", container.getName()));
public PagedIterable<BlobContainerItem> listBlobContainers(ListBlobContainersOptions options, Duration timeout)
PagedIterable
can be consumed
while new items are automatically retrieved as needed. For more information, see the Azure Docs.
Code Samples
ListBlobContainersOptions
options = newListBlobContainersOptions
() .setPrefix("containerNamePrefixToMatch") .setDetails(newBlobContainerListDetails
().setRetrieveMetadata(true)); client.listBlobContainers(options, timeout).forEach(container ->System
.out.printf("Name: %s%n", container.getName()));
options
- A ListBlobContainersOptions
which specifies what data should be returned by the service.timeout
- An optional timeout value beyond which a RuntimeException
will be raised.public BlobServiceProperties getProperties()
Code Samples
BlobServiceProperties
properties = client.getProperties();System
.out.printf("Hour metrics enabled: %b, Minute metrics enabled: %b%n", properties.getHourMetrics().isEnabled(), properties.getMinuteMetrics().isEnabled());
public Response<BlobServiceProperties> getPropertiesWithResponse(Duration timeout, Context context)
Code Samples
Context
context = newContext
("Key", "Value");BlobServiceProperties
properties = client.getPropertiesWithResponse(timeout, context).getValue();System
.out.printf("Hour metrics enabled: %b, Minute metrics enabled: %b%n", properties.getHourMetrics().isEnabled(), properties.getMinuteMetrics().isEnabled());
timeout
- An optional timeout value beyond which a RuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.Response
whose value
contains the storage account properties.public void setProperties(BlobServiceProperties properties)
Code Samples
BlobRetentionPolicy
loggingRetentionPolicy = newBlobRetentionPolicy
().setEnabled(true).setDays(3);BlobRetentionPolicy
metricsRetentionPolicy = newBlobRetentionPolicy
().setEnabled(true).setDays(1);BlobServiceProperties
properties = newBlobServiceProperties
() .setLogging(newBlobAnalyticsLogging
() .setWrite(true) .setDelete(true) .setRetentionPolicy(loggingRetentionPolicy)) .setHourMetrics(newBlobMetrics
() .setEnabled(true) .setRetentionPolicy(metricsRetentionPolicy)) .setMinuteMetrics(newBlobMetrics
() .setEnabled(true) .setRetentionPolicy(metricsRetentionPolicy)); try { client.setProperties(properties);System
.out.printf("Setting properties completed%n"); } catch (UnsupportedOperationException
error) {System
.out.printf("Setting properties failed: %s%n", error); }
properties
- Configures the service.public Response<Void> setPropertiesWithResponse(BlobServiceProperties properties, Duration timeout, Context context)
Code Samples
BlobRetentionPolicy
loggingRetentionPolicy = newBlobRetentionPolicy
().setEnabled(true).setDays(3);BlobRetentionPolicy
metricsRetentionPolicy = newBlobRetentionPolicy
().setEnabled(true).setDays(1);BlobServiceProperties
properties = newBlobServiceProperties
() .setLogging(newBlobAnalyticsLogging
() .setWrite(true) .setDelete(true) .setRetentionPolicy(loggingRetentionPolicy)) .setHourMetrics(newBlobMetrics
() .setEnabled(true) .setRetentionPolicy(metricsRetentionPolicy)) .setMinuteMetrics(newBlobMetrics
() .setEnabled(true) .setRetentionPolicy(metricsRetentionPolicy));Context
context = newContext
("Key", "Value");System
.out.printf("Setting properties completed with status %d%n", client.setPropertiesWithResponse(properties, timeout, context).getStatusCode());
properties
- Configures the service.timeout
- An optional timeout value beyond which a RuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.public UserDelegationKey getUserDelegationKey(OffsetDateTime start, OffsetDateTime expiry)
TokenCredential
in this object's HttpPipeline
.
Code Samples
System
.out.printf("User delegation key: %s%n",
client.getUserDelegationKey(delegationKeyStartTime, delegationKeyExpiryTime));
start
- Start time for the key's validity. Null indicates immediate start.expiry
- Expiration of the key's validity.public Response<UserDelegationKey> getUserDelegationKeyWithResponse(OffsetDateTime start, OffsetDateTime expiry, Duration timeout, Context context)
TokenCredential
in this object's HttpPipeline
.
Code Samples
System
.out.printf("User delegation key: %s%n",
client.getUserDelegationKeyWithResponse(delegationKeyStartTime, delegationKeyExpiryTime, timeout, context));
start
- Start time for the key's validity. Null indicates immediate start.expiry
- Expiration of the key's validity.timeout
- An optional timeout value beyond which a RuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.Response
whose value
contains the user delegation key.public BlobServiceStatistics getStatistics()
Code Samples
System
.out.printf("Geo-replication status: %s%n",
client.getStatistics().getGeoReplication().getStatus());
public Response<BlobServiceStatistics> getStatisticsWithResponse(Duration timeout, Context context)
Code Samples
System
.out.printf("Geo-replication status: %s%n",
client.getStatisticsWithResponse(timeout, context).getValue().getGeoReplication().getStatus());
timeout
- An optional timeout value beyond which a RuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.Response
whose value
the storage account statistics.public StorageAccountInfo getAccountInfo()
Code Samples
StorageAccountInfo
accountInfo = client.getAccountInfo();System
.out.printf("Account kind: %s, SKU: %s%n", accountInfo.getAccountKind(), accountInfo.getSkuName());
public Response<StorageAccountInfo> getAccountInfoWithResponse(Duration timeout, Context context)
timeout
- An optional timeout value beyond which a RuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.Response
whose value
contains the storage account info.public String getAccountName()
Copyright © 2019 Microsoft Corporation. All rights reserved.