public final class BlobContainerClient extends Object
BlobContainerClientBuilder or via the method
BlobServiceClient.getBlobContainerClient(String). This class does not hold any state about a particular
container 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 BlobClient through
BlobContainerClient.getBlobClient(String), and operations on the service are available on BlobServiceClient.
Please refer to the Azure Docs for more information on containers.
| 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 |
|---|---|
void |
create()
Creates a new container within a storage account.
|
com.azure.core.http.rest.Response<Void> |
createWithResponse(Map<String,String> metadata,
PublicAccessType accessType,
Duration timeout,
com.azure.core.util.Context context)
Creates a new container within a storage account.
|
void |
delete()
Marks the specified container for deletion.
|
com.azure.core.http.rest.Response<Void> |
deleteWithResponse(BlobRequestConditions requestConditions,
Duration timeout,
com.azure.core.util.Context context)
Marks the specified container for deletion.
|
boolean |
exists()
Gets if the container this client represents exists in the cloud.
|
com.azure.core.http.rest.Response<Boolean> |
existsWithResponse(Duration timeout,
com.azure.core.util.Context context)
Gets if the container this client represents exists in the cloud.
|
String |
generateSas(BlobServiceSasSignatureValues blobServiceSasSignatureValues)
Generates a service SAS for the container using the specified
BlobServiceSasSignatureValues
Note : The client must be authenticated via StorageSharedKeyCredential |
String |
generateUserDelegationSas(BlobServiceSasSignatureValues blobServiceSasSignatureValues,
UserDelegationKey userDelegationKey)
Generates a user delegation SAS for the container using the specified
BlobServiceSasSignatureValues. |
BlobContainerAccessPolicies |
getAccessPolicy()
Returns the container's permissions.
|
com.azure.core.http.rest.Response<BlobContainerAccessPolicies> |
getAccessPolicyWithResponse(String leaseId,
Duration timeout,
com.azure.core.util.Context context)
Returns the container's permissions.
|
StorageAccountInfo |
getAccountInfo(Duration timeout)
Returns the sku name and account kind for the account.
|
com.azure.core.http.rest.Response<StorageAccountInfo> |
getAccountInfoWithResponse(Duration timeout,
com.azure.core.util.Context context)
Returns the sku name and account kind for the account.
|
String |
getAccountName()
Get associated account name.
|
BlobClient |
getBlobClient(String blobName)
Initializes a new BlobClient object by concatenating blobName to the end of ContainerAsyncClient's URL.
|
BlobClient |
getBlobClient(String blobName,
String snapshot)
Initializes a new BlobClient 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 BlobClients when
getBlobClient is called. |
com.azure.core.http.HttpPipeline |
getHttpPipeline()
Gets the
HttpPipeline powering this client. |
BlobContainerProperties |
getProperties()
Returns the container's metadata and system properties.
|
com.azure.core.http.rest.Response<BlobContainerProperties> |
getPropertiesWithResponse(String leaseId,
Duration timeout,
com.azure.core.util.Context context)
Returns the container's metadata and system properties.
|
BlobServiceVersion |
getServiceVersion()
Gets the service version the client is using.
|
com.azure.core.http.rest.PagedIterable<BlobItem> |
listBlobs()
Returns a lazy loaded list of blobs in this container, with folder structures flattened.
|
com.azure.core.http.rest.PagedIterable<BlobItem> |
listBlobs(ListBlobsOptions options,
Duration timeout)
Returns a lazy loaded list of blobs in this container, with folder structures flattened.
|
com.azure.core.http.rest.PagedIterable<BlobItem> |
listBlobsByHierarchy(String directory)
Returns a reactive Publisher emitting all the blobs and directories (prefixes) under the given directory
(prefix).
|
com.azure.core.http.rest.PagedIterable<BlobItem> |
listBlobsByHierarchy(String delimiter,
ListBlobsOptions options,
Duration timeout)
Returns a reactive Publisher emitting all the blobs and prefixes (directories) under the given prefix
(directory).
|
void |
setAccessPolicy(PublicAccessType accessType,
List<BlobSignedIdentifier> identifiers)
Sets the container's permissions.
|
com.azure.core.http.rest.Response<Void> |
setAccessPolicyWithResponse(PublicAccessType accessType,
List<BlobSignedIdentifier> identifiers,
BlobRequestConditions requestConditions,
Duration timeout,
com.azure.core.util.Context context)
Sets the container's permissions.
|
void |
setMetadata(Map<String,String> metadata)
Sets the container's metadata.
|
com.azure.core.http.rest.Response<Void> |
setMetadataWithResponse(Map<String,String> metadata,
BlobRequestConditions requestConditions,
Duration timeout,
com.azure.core.util.Context context)
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 BlobClient getBlobClient(String blobName)
blobName - A String representing the name of the blob.
Code Samples
BlobClient blobClient = client.getBlobClient(blobName);
BlobClient object which references the blob with the specified name in this container.public BlobClient getBlobClient(String blobName, String snapshot)
Code Samples
BlobClient blobClient = client.getBlobClient(blobName, snapshot);
blobName - A String representing the name of the blob.snapshot - the snapshot identifier for the blob.BlobClient object which references the blob with the specified name in this container.public String getBlobContainerName()
Code Samples
StringcontainerName = client.getBlobContainerName();System.out.println("The name of the blob is " + containerName);
public String getBlobContainerUrl()
public String getAccountName()
public BlobServiceVersion getServiceVersion()
public com.azure.core.http.HttpPipeline getHttpPipeline()
HttpPipeline powering this client.public CpkInfo getCustomerProvidedKey()
CpkInfo associated with this client that will be passed to BlobClients when
getBlobClient is called.public boolean exists()
Code Samples
System.out.printf("Exists? %b%n", client.exists());
public com.azure.core.http.rest.Response<Boolean> existsWithResponse(Duration timeout, com.azure.core.util.Context context)
Code Samples
Contextcontext = newContext("Key", "Value");System.out.printf("Exists? %b%n", client.existsWithResponse(timeout, context).getValue());
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 void create()
Code Samples
try {
client.create();
System.out.printf("Create completed%n");
} catch (BlobStorageException error) {
if (error.getErrorCode().equals(BlobErrorCode.CONTAINER_ALREADY_EXISTS)) {
System.out.printf("Can't create container. It already exists %n");
}
}
public com.azure.core.http.rest.Response<Void> createWithResponse(Map<String,String> metadata, PublicAccessType accessType, Duration timeout, com.azure.core.util.Context context)
Code Samples
Map<String,String> metadata =Collections.singletonMap("metadata", "value");Contextcontext = newContext("Key", "Value");System.out.printf("Create completed with status %d%n", client.createWithResponse(metadata,PublicAccessType.CONTAINER, timeout, context).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.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 void delete()
Code Samples
try {
client.delete();
System.out.printf("Delete completed%n");
} catch (BlobStorageException error) {
if (error.getErrorCode().equals(BlobErrorCode.CONTAINER_NOT_FOUND)) {
System.out.printf("Delete failed. Container was not found %n");
}
}
public com.azure.core.http.rest.Response<Void> deleteWithResponse(BlobRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context)
Code Samples
BlobRequestConditionsrequestConditions = newBlobRequestConditions() .setLeaseId(leaseId) .setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));Contextcontext = newContext("Key", "Value");System.out.printf("Delete completed with status %d%n", client.deleteWithResponse( requestConditions, timeout, context).getStatusCode());
requestConditions - BlobRequestConditionstimeout - 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 BlobContainerProperties getProperties()
Code Samples
BlobContainerPropertiesproperties = client.getProperties();System.out.printf("Public Access Type: %s, Legal Hold? %b, Immutable? %b%n", properties.getBlobPublicAccess(), properties.hasLegalHold(), properties.hasImmutabilityPolicy());
public com.azure.core.http.rest.Response<BlobContainerProperties> getPropertiesWithResponse(String leaseId, Duration timeout, com.azure.core.util.Context context)
Code Samples
Contextcontext = newContext("Key", "Value");BlobContainerPropertiesproperties = client.getPropertiesWithResponse(leaseId, timeout, context) .getValue();System.out.printf("Public Access Type: %s, Legal Hold? %b, Immutable? %b%n", properties.getBlobPublicAccess(), properties.hasLegalHold(), properties.hasImmutabilityPolicy());
leaseId - The lease ID the active lease on the container must match.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 void setMetadata(Map<String,String> metadata)
Code Samples
Map<String,String> metadata =Collections.singletonMap("metadata", "value"); try { client.setMetadata(metadata);System.out.printf("Set metadata completed with status %n"); } catch (UnsupportedOperationExceptionerror) {System.out.printf("Fail while setting metadata %n"); }
metadata - Metadata to associate with the container.public com.azure.core.http.rest.Response<Void> setMetadataWithResponse(Map<String,String> metadata, BlobRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context)
Code Samples
Map<String,String> metadata =Collections.singletonMap("metadata", "value");BlobRequestConditionsrequestConditions = newBlobRequestConditions() .setLeaseId(leaseId) .setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));Contextcontext = newContext("Key", "Value");System.out.printf("Set metadata completed with status %d%n", client.setMetadataWithResponse(metadata, requestConditions, timeout, context).getStatusCode());
metadata - Metadata to associate with the container.requestConditions - BlobRequestConditionstimeout - 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 BlobContainerAccessPolicies getAccessPolicy()
Code Samples
BlobContainerAccessPoliciesaccessPolicies = client.getAccessPolicy();System.out.printf("Blob Access Type: %s%n", accessPolicies.getBlobAccessType()); for (BlobSignedIdentifieridentifier : accessPolicies.getIdentifiers()) {System.out.printf("Identifier Name: %s, Permissions %s%n", identifier.getId(), identifier.getAccessPolicy().getPermissions()); }
public com.azure.core.http.rest.Response<BlobContainerAccessPolicies> getAccessPolicyWithResponse(String leaseId, Duration timeout, com.azure.core.util.Context context)
Code Samples
Contextcontext = newContext("Key", "Value");BlobContainerAccessPoliciesaccessPolicies = client.getAccessPolicyWithResponse(leaseId, timeout, context) .getValue();System.out.printf("Blob Access Type: %s%n", accessPolicies.getBlobAccessType()); for (BlobSignedIdentifieridentifier : accessPolicies.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.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 void setAccessPolicy(PublicAccessType accessType, List<BlobSignedIdentifier> identifiers)
Code Samples
BlobSignedIdentifieridentifier = newBlobSignedIdentifier() .setId("name") .setAccessPolicy(newBlobAccessPolicy() .setStartsOn(OffsetDateTime.now()) .setExpiresOn(OffsetDateTime.now().plusDays(7)) .setPermissions("permissionString")); try { client.setAccessPolicy(PublicAccessType.CONTAINER,Collections.singletonList(identifier));System.out.printf("Set Access Policy completed %n"); } catch (UnsupportedOperationExceptionerror) {System.out.printf("Set Access Policy completed %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 com.azure.core.http.rest.Response<Void> setAccessPolicyWithResponse(PublicAccessType accessType, List<BlobSignedIdentifier> identifiers, BlobRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context)
Code Samples
BlobSignedIdentifieridentifier = newBlobSignedIdentifier() .setId("name") .setAccessPolicy(newBlobAccessPolicy() .setStartsOn(OffsetDateTime.now()) .setExpiresOn(OffsetDateTime.now().plusDays(7)) .setPermissions("permissionString"));BlobRequestConditionsrequestConditions = newBlobRequestConditions() .setLeaseId(leaseId) .setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));Contextcontext = newContext("Key", "Value");System.out.printf("Set access policy completed with status %d%n", client.setAccessPolicyWithResponse(PublicAccessType.CONTAINER,Collections.singletonList(identifier), requestConditions, timeout, context).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.requestConditions - BlobRequestConditionstimeout - 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 com.azure.core.http.rest.PagedIterable<BlobItem> listBlobs()
PagedIterable can be consumed through while new items are automatically retrieved as needed.
Blob names are returned in lexicographic order.
For more information, see the Azure Docs.
Code Samples
client.listBlobs().forEach(blob ->
System.out.printf("Name: %s, Directory? %b%n", blob.getName(), blob.isPrefix()));
public com.azure.core.http.rest.PagedIterable<BlobItem> listBlobs(ListBlobsOptions options, Duration timeout)
PagedIterable can be consumed through while new items are automatically retrieved as needed.
Blob names are returned in lexicographic order.
For more information, see the Azure Docs.
Code Samples
ListBlobsOptionsoptions = newListBlobsOptions() .setPrefix("prefixToMatch") .setDetails(newBlobListDetails() .setRetrieveDeletedBlobs(true) .setRetrieveSnapshots(true)); client.listBlobs(options, timeout).forEach(blob ->System.out.printf("Name: %s, Directory? %b, Deleted? %b, Snapshot ID: %s%n", blob.getName(), blob.isPrefix(), blob.isDeleted(), blob.getSnapshot()));
options - ListBlobsOptionstimeout - An optional timeout value beyond which a RuntimeException will be raised.public com.azure.core.http.rest.PagedIterable<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").forEach(blob ->
System.out.printf("Name: %s, Directory? %b%n", blob.getName(), blob.isPrefix()));
directory - The directory to list blobs underneathpublic com.azure.core.http.rest.PagedIterable<BlobItem> listBlobsByHierarchy(String delimiter, ListBlobsOptions options, Duration timeout)
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
ListBlobsOptionsoptions = newListBlobsOptions() .setPrefix("directoryName") .setDetails(newBlobListDetails() .setRetrieveDeletedBlobs(true) .setRetrieveSnapshots(true)); client.listBlobsByHierarchy("/", options, timeout).forEach(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 - ListBlobsOptionstimeout - An optional timeout value beyond which a RuntimeException will be raised.public StorageAccountInfo getAccountInfo(Duration timeout)
timeout - An optional timeout value beyond which a RuntimeException will be raised.
Code Samples
StorageAccountInfoaccountInfo = client.getAccountInfo(timeout);System.out.printf("Account Kind: %s, SKU: %s%n", accountInfo.getAccountKind(), accountInfo.getSkuName());
public com.azure.core.http.rest.Response<StorageAccountInfo> getAccountInfoWithResponse(Duration timeout, com.azure.core.util.Context context)
Code Samples
Contextcontext = newContext("Key", "Value");StorageAccountInfoaccountInfo = client.getAccountInfoWithResponse(timeout, context).getValue();System.out.printf("Account Kind: %s, SKU: %s%n", accountInfo.getAccountKind(), accountInfo.getSkuName());
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 String generateUserDelegationSas(BlobServiceSasSignatureValues blobServiceSasSignatureValues, UserDelegationKey userDelegationKey)
BlobServiceSasSignatureValues.
See BlobServiceSasSignatureValues for more information on how to construct a user delegation SAS.
Code Samples
OffsetDateTimemyExpiryTime =OffsetDateTime.now().plusDays(1);BlobContainerSasPermissionmyPermission = newBlobContainerSasPermission().setReadPermission(true);BlobServiceSasSignatureValuesmyValues = newBlobServiceSasSignatureValues(expiryTime, permission) .setStartTime(OffsetDateTime.now()); client.generateUserDelegationSas(values, userDelegationKey);
blobServiceSasSignatureValues - BlobServiceSasSignatureValuesuserDelegationKey - A UserDelegationKey object used to sign the SAS values.String representing all SAS query parameters.for more information on how to get a
user delegation key.public String generateSas(BlobServiceSasSignatureValues blobServiceSasSignatureValues)
BlobServiceSasSignatureValues
Note : The client must be authenticated via StorageSharedKeyCredential
See BlobServiceSasSignatureValues for more information on how to construct a service SAS.
Code Samples
OffsetDateTimeexpiryTime =OffsetDateTime.now().plusDays(1);BlobContainerSasPermissionpermission = newBlobContainerSasPermission().setReadPermission(true);BlobServiceSasSignatureValuesvalues = newBlobServiceSasSignatureValues(expiryTime, permission) .setStartTime(OffsetDateTime.now()); client.generateSas(values); // Client must be authenticated via StorageSharedKeyCredential
blobServiceSasSignatureValues - BlobServiceSasSignatureValuesString representing all SAS query parameters.Copyright © 2020 Microsoft Corporation. All rights reserved.