Class BlobContainerClient
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
getBlobClient(String)
, and operations on the service are available on BlobServiceClient
.
Please refer to the Azure Docs for more information on containers.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Special container name for the logs container in the Storage account.static final String
Special container name for the root container in the Storage account.static final String
Special container name for the static website container in the Storage account. -
Method Summary
Modifier and TypeMethodDescriptionvoid
create()
Creates a new container within a storage account.boolean
Creates a new container within a storage account if it does not exist.com.azure.core.http.rest.Response<Boolean>
createIfNotExistsWithResponse
(BlobContainerCreateOptions options, Duration timeout, com.azure.core.util.Context context) Creates a new container within a storage account if it does not exist.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.boolean
Marks the specified container for deletion if it exists.com.azure.core.http.rest.Response<Boolean>
deleteIfExistsWithResponse
(BlobRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context) Marks the specified container for deletion if it exists.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.com.azure.core.http.rest.PagedIterable<TaggedBlobItem>
findBlobsByTags
(FindBlobsOptions options, Duration timeout, com.azure.core.util.Context context) Returns a lazy loaded list of blobs in this account whose tags match the query expression.com.azure.core.http.rest.PagedIterable<TaggedBlobItem>
findBlobsByTags
(String query) Returns a lazy loaded list of blobs in this container whose tags match the query expression.generateSas
(BlobServiceSasSignatureValues blobServiceSasSignatureValues) Generates a service SAS for the container using the specifiedBlobServiceSasSignatureValues
generateSas
(BlobServiceSasSignatureValues blobServiceSasSignatureValues, com.azure.core.util.Context context) Generates a service SAS for the container using the specifiedBlobServiceSasSignatureValues
generateUserDelegationSas
(BlobServiceSasSignatureValues blobServiceSasSignatureValues, UserDelegationKey userDelegationKey) Generates a user delegation SAS for the container using the specifiedBlobServiceSasSignatureValues
.generateUserDelegationSas
(BlobServiceSasSignatureValues blobServiceSasSignatureValues, UserDelegationKey userDelegationKey, String accountName, com.azure.core.util.Context context) Generates a user delegation SAS for the container using the specifiedBlobServiceSasSignatureValues
.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.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.Get associated account name.Get the url of the storage account.getBlobClient
(String blobName) Initializes a new BlobClient object by concatenating blobName to the end of ContainerAsyncClient's URL.getBlobClient
(String blobName, String snapshot) Initializes a new BlobClient object by concatenating blobName to the end of ContainerAsyncClient's URL.Get the container name.Gets the URL of the container represented by this client.getBlobVersionClient
(String blobName, String versionId) Initializes a new BlobClient object by concatenating blobName to the end of ContainerAsyncClient's URL.Gets theCpkInfo
associated with this client that will be passed toBlobClients
whengetBlobClient
is called.Gets theencryption scope
used to encrypt this blob's content on the server.com.azure.core.http.HttpPipeline
Gets theHttpPipeline
powering this client.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.Get a client pointing to the account.Gets the service version the client is using.com.azure.core.http.rest.PagedIterable<BlobItem>
Returns a lazy loaded list of blobs in this container, with folder structures flattened.com.azure.core.http.rest.PagedIterable<BlobItem>
listBlobs
(ListBlobsOptions options, String continuationToken, Duration timeout) 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.
-
Field Details
-
ROOT_CONTAINER_NAME
Special container name for the root container in the Storage account.- See Also:
-
STATIC_WEBSITE_CONTAINER_NAME
Special container name for the static website container in the Storage account.- See Also:
-
LOG_CONTAINER_NAME
Special container name for the logs container in the Storage account.- See Also:
-
-
Method Details
-
getBlobClient
Initializes a new BlobClient object by concatenating blobName to the end of ContainerAsyncClient's URL. The new BlobClient uses the same request policy pipeline as the ContainerAsyncClient.- Parameters:
blobName
- AString
representing the name of the blob. If the blob name contains special characters, pass in the url encoded version of the blob name.Code Samples
BlobClient blobClient = client.getBlobClient(blobName);
- Returns:
- A new
BlobClient
object which references the blob with the specified name in this container.
-
getBlobClient
Initializes a new BlobClient object by concatenating blobName to the end of ContainerAsyncClient's URL. The new BlobClient uses the same request policy pipeline as the ContainerAsyncClient.Code Samples
BlobClient blobClient = client.getBlobClient(blobName, snapshot);
- Parameters:
blobName
- AString
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
BlobClient
object which references the blob with the specified name in this container.
-
getBlobVersionClient
Initializes a new BlobClient object by concatenating blobName to the end of ContainerAsyncClient's URL. The new BlobClient uses the same request policy pipeline as the ContainerAsyncClient.- Parameters:
blobName
- AString
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, passnull
to interact with the latest blob version.- Returns:
- A new
BlobClient
object which references the blob with the specified name in this container.
-
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.
-
getAccountUrl
Get the url of the storage account.- Returns:
- the URL of the storage account
-
getBlobContainerUrl
Gets the URL of the container represented by this client.- Returns:
- the URL.
-
getAccountName
Get associated account name.- Returns:
- account name associated with this storage resource.
-
getServiceClient
Get a client pointing to the account.- Returns:
BlobServiceClient
-
getServiceVersion
Gets the service version the client is using.- Returns:
- the service version the client is using.
-
getHttpPipeline
public com.azure.core.http.HttpPipeline getHttpPipeline()Gets theHttpPipeline
powering this client.- Returns:
- The pipeline.
-
getCustomerProvidedKey
Gets theCpkInfo
associated with this client that will be passed toBlobClients
whengetBlobClient
is called.- Returns:
- the customer provided key used for encryption.
-
getEncryptionScope
Gets theencryption scope
used to encrypt this blob's content on the server.- Returns:
- the encryption scope used for encryption.
-
exists
public boolean exists()Gets if the container this client represents exists in the cloud.Code Samples
System.out.printf("Exists? %b%n", client.exists());
- Returns:
- true if the container exists, false if it doesn't
-
existsWithResponse
public 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.Code Samples
Context context = new Context("Key", "Value"); System.out.printf("Exists? %b%n", client.existsWithResponse(timeout, context).getValue());
- Parameters:
timeout
- An optional timeout value beyond which aRuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- true if the container exists, false if it doesn't
-
create
public void 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
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"); } }
-
createWithResponse
public 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. 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"); Context context = new Context("Key", "Value"); System.out.printf("Create completed with status %d%n", client.createWithResponse(metadata, PublicAccessType.CONTAINER, timeout, context).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.timeout
- An optional timeout value beyond which aRuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response containing status code and HTTP headers
-
createIfNotExists
public boolean createIfNotExists()Creates a new container within a storage account if it does not exist. For more information, see the Azure Docs.Code Samples
boolean result = client.createIfNotExists(); System.out.println("Create completed: " + result);
- Returns:
true
if container is successfully created,false
if container already exists.
-
createIfNotExistsWithResponse
public com.azure.core.http.rest.Response<Boolean> createIfNotExistsWithResponse(BlobContainerCreateOptions options, Duration timeout, com.azure.core.util.Context context) 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"); Context context = new Context("Key", "Value"); BlobContainerCreateOptions options = new BlobContainerCreateOptions().setMetadata(metadata) .setPublicAccessType(PublicAccessType.CONTAINER); Response<Boolean> response = client.createIfNotExistsWithResponse(options, timeout, context); if (response.getStatusCode() == 409) { System.out.println("Already existed."); } else { System.out.printf("Create completed with status %d%n", response.getStatusCode()); }
- Parameters:
options
-BlobContainerCreateOptions
timeout
- An optional timeout value beyond which aRuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response containing status code and HTTP headers. If
Response
's status code is 201, a new container was successfully created. If status code is 409, a container already existed at this location.
-
delete
public void 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
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"); } }
-
deleteWithResponse
public com.azure.core.http.rest.Response<Void> deleteWithResponse(BlobRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context) 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)); Context context = new Context("Key", "Value"); System.out.printf("Delete completed with status %d%n", client.deleteWithResponse( requestConditions, timeout, context).getStatusCode());
- Parameters:
requestConditions
-BlobRequestConditions
timeout
- An optional timeout value beyond which aRuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response containing status code and HTTP headers
-
deleteIfExists
public boolean 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
boolean result = client.deleteIfExists(); System.out.println("Delete completed: " + result);
- Returns:
true
if container is successfully deleted,false
if container does not exist.
-
deleteIfExistsWithResponse
public com.azure.core.http.rest.Response<Boolean> deleteIfExistsWithResponse(BlobRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context) 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)); Context context = new Context("Key", "Value"); Response<Boolean> response = client.deleteIfExistsWithResponse(requestConditions, timeout, context); if (response.getStatusCode() == 404) { System.out.println("Does not exist."); } else { System.out.printf("Delete completed with status %d%n", response.getStatusCode()); }
- Parameters:
requestConditions
-BlobRequestConditions
timeout
- An optional timeout value beyond which aRuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response containing status code and HTTP headers. If
Response
's status code is 202, the container was successfully deleted. If status code is 404, the container does not exist.
-
getProperties
Returns the container's metadata and system properties. For more information, see the Azure Docs.Code Samples
BlobContainerProperties properties = client.getProperties(); System.out.printf("Public Access Type: %s, Legal Hold? %b, Immutable? %b%n", properties.getBlobPublicAccess(), properties.hasLegalHold(), properties.hasImmutabilityPolicy());
- Returns:
- The container properties.
-
getPropertiesWithResponse
public 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. For more information, see the Azure Docs.Code Samples
Context context = new Context("Key", "Value"); BlobContainerProperties properties = 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());
- Parameters:
leaseId
- The lease ID the active lease on the container must match.timeout
- An optional timeout value beyond which aRuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- The container properties.
-
setMetadata
Sets the container's metadata. For more information, see the Azure Docs.Code Samples
Map<String, String> metadata = Collections.singletonMap("metadata", "value"); try { client.setMetadata(metadata); System.out.printf("Set metadata completed with status %n"); } catch (UnsupportedOperationException error) { System.out.printf("Fail while setting metadata %n"); }
- 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.
-
setMetadataWithResponse
public 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. 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)); Context context = new Context("Key", "Value"); System.out.printf("Set metadata completed with status %d%n", client.setMetadataWithResponse(metadata, requestConditions, timeout, context).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
timeout
- An optional timeout value beyond which aRuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response containing status code and HTTP headers
-
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
BlobContainerAccessPolicies accessPolicies = client.getAccessPolicy(); System.out.printf("Blob Access Type: %s%n", accessPolicies.getBlobAccessType()); for (BlobSignedIdentifier identifier : accessPolicies.getIdentifiers()) { System.out.printf("Identifier Name: %s, Permissions %s%n", identifier.getId(), identifier.getAccessPolicy().getPermissions()); }
- Returns:
- The container access policy.
-
getAccessPolicyWithResponse
public com.azure.core.http.rest.Response<BlobContainerAccessPolicies> getAccessPolicyWithResponse(String leaseId, Duration timeout, com.azure.core.util.Context context) 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
Context context = new Context("Key", "Value"); BlobContainerAccessPolicies accessPolicies = client.getAccessPolicyWithResponse(leaseId, timeout, context) .getValue(); System.out.printf("Blob Access Type: %s%n", accessPolicies.getBlobAccessType()); for (BlobSignedIdentifier identifier : accessPolicies.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.timeout
- An optional timeout value beyond which aRuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- The container access policy.
-
setAccessPolicy
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")); try { client.setAccessPolicy(PublicAccessType.CONTAINER, Collections.singletonList(identifier)); System.out.printf("Set Access Policy completed %n"); } catch (UnsupportedOperationException error) { System.out.printf("Set Access Policy completed %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 ofBlobSignedIdentifier
objects that specify the permissions for the container. Please see here for more information. Passing null will clear all access policies.
-
setAccessPolicyWithResponse
public 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. 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)); Context context = new Context("Key", "Value"); System.out.printf("Set access policy completed with status %d%n", client.setAccessPolicyWithResponse(PublicAccessType.CONTAINER, Collections.singletonList(identifier), requestConditions, timeout, context).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 ofBlobSignedIdentifier
objects that specify the permissions for the container. Please see here for more information. Passing null will clear all access policies.requestConditions
-BlobRequestConditions
timeout
- An optional timeout value beyond which aRuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response containing status code and HTTP headers
-
listBlobs
Returns a lazy loaded list of blobs in this container, with folder structures flattened. The returnedPagedIterable
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()));
- Returns:
- The listed blobs, flattened.
-
listBlobs
public 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. The returnedPagedIterable
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
ListBlobsOptions options = new ListBlobsOptions() .setPrefix("prefixToMatch") .setDetails(new BlobListDetails() .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()));
- Parameters:
options
-ListBlobsOptions
. If iterating by page, the page size passed to byPage methods such asContinuablePagedIterable.iterableByPage(int)
will be preferred over the value set on these options.timeout
- An optional timeout value beyond which aRuntimeException
will be raised.- Returns:
- The listed blobs, flattened.
-
listBlobs
public com.azure.core.http.rest.PagedIterable<BlobItem> listBlobs(ListBlobsOptions options, String continuationToken, Duration timeout) Returns a lazy loaded list of blobs in this container, with folder structures flattened. The returnedPagedIterable
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
ListBlobsOptions options = new ListBlobsOptions() .setPrefix("prefixToMatch") .setDetails(new BlobListDetails() .setRetrieveDeletedBlobs(true) .setRetrieveSnapshots(true)); String continuationToken = "continuationToken"; client.listBlobs(options, continuationToken, timeout).forEach(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
. If iterating by page, the page size passed to byPage methods such asContinuablePagedIterable.iterableByPage(int)
will be preferred over the value set on these options.continuationToken
- Identifies the portion of the list to be returned with the next list operation.timeout
- An optional timeout value beyond which aRuntimeException
will be raised.- Returns:
- The listed blobs, flattened.
-
listBlobsByHierarchy
Returns a reactive Publisher emitting all the blobs and directories (prefixes) under the given directory (prefix). Directories will haveBlobItem.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").forEach(blob -> System.out.printf("Name: %s, Directory? %b%n", blob.getName(), blob.isPrefix()));
- Parameters:
directory
- The directory to list blobs underneath- Returns:
- A reactive response emitting the prefixes and blobs.
-
listBlobsByHierarchy
public 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). Directories will haveBlobItem.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, timeout).forEach(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 directoriesoptions
-ListBlobsOptions
. If iterating by page, the page size passed to byPage methods such asContinuablePagedIterable.iterableByPage(int)
will be preferred over the value set on these options.timeout
- An optional timeout value beyond which aRuntimeException
will be raised.- Returns:
- A reactive response emitting the prefixes and blobs.
-
findBlobsByTags
Returns a lazy loaded list of blobs in this container whose tags match the query expression. The returnedPagedIterable
can be consumed while new items are automatically retrieved as needed. For more information, including information on the query syntax, see the Azure Docs.Code Samples
TODOclient.findBlobsByTags("where=tag=value").forEach(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:
- The list of blobs.
-
findBlobsByTags
public com.azure.core.http.rest.PagedIterable<TaggedBlobItem> findBlobsByTags(FindBlobsOptions options, Duration timeout, com.azure.core.util.Context context) Returns a lazy loaded list of blobs in this account whose tags match the query expression. The returnedPagedIterable
can be consumed while new items are automatically retrieved as needed. For more information, including information on the query syntax, see the Azure Docs.Code Samples
Context context = new Context("Key", "Value"); client.findBlobsByTags(new FindBlobsOptions("where=tag=value").setMaxResultsPerPage(10), timeout, context) .forEach(blob -> System.out.printf("Name: %s%n", blob.getName()));
- Parameters:
options
-FindBlobsOptions
. If iterating by page, the page size passed to byPage methods such asContinuablePagedIterable.iterableByPage(int)
will be preferred over the value set on these options.timeout
- An optional timeout value beyond which aRuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- The list of blobs.
-
getAccountInfo
Returns the sku name and account kind for the account. For more information, please see the Azure Docs.- Parameters:
timeout
- An optional timeout value beyond which aRuntimeException
will be raised.Code Samples
StorageAccountInfo accountInfo = client.getAccountInfo(timeout); System.out.printf("Account Kind: %s, SKU: %s%n", accountInfo.getAccountKind(), accountInfo.getSkuName());
- Returns:
- The account info.
-
getAccountInfoWithResponse
public 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. For more information, please see the Azure Docs.Code Samples
Context context = new Context("Key", "Value"); StorageAccountInfo accountInfo = client.getAccountInfoWithResponse(timeout, context).getValue(); System.out.printf("Account Kind: %s, SKU: %s%n", accountInfo.getAccountKind(), accountInfo.getSkuName());
- Parameters:
timeout
- An optional timeout value beyond which aRuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- The account info.
-
generateUserDelegationSas
public String generateUserDelegationSas(BlobServiceSasSignatureValues blobServiceSasSignatureValues, UserDelegationKey userDelegationKey) Generates a user delegation SAS for the container using the specifiedBlobServiceSasSignatureValues
.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
- AUserDelegationKey
object used to sign the SAS values. SeeBlobServiceClient.getUserDelegationKey(OffsetDateTime, OffsetDateTime)
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, com.azure.core.util.Context context) Generates a user delegation SAS for the container using the specifiedBlobServiceSasSignatureValues
.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
- AUserDelegationKey
object used to sign the SAS values. SeeBlobServiceClient.getUserDelegationKey(OffsetDateTime, OffsetDateTime)
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.
-
generateSas
Generates a service SAS for the container using the specifiedBlobServiceSasSignatureValues
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, com.azure.core.util.Context context) Generates a service SAS for the container using the specifiedBlobServiceSasSignatureValues
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.
-