EncryptedBlobAsyncClient Class

public class EncryptedBlobAsyncClient
extends BlobAsyncClient

This class provides a client side encryption client that contains generic blob operations for Azure Storage Blobs. Operations allowed by the client are uploading, downloading and copying a blob, retrieving and setting metadata, retrieving and setting HTTP headers, and deleting and un-deleting a blob. The upload and download operation allow for encryption and decryption of the data client side. Note: setting metadata in particular is unsafe and should only be done so with caution.

Please refer to the Azure Docs For Client-Side Encryption for more information.

This client is instantiated through EncryptedBlobClientBuilder

For operations on a specific blob type (i.e. append, block, or page) use getAppendBlobAsyncClient, getBlockBlobAsyncClient, or getPageBlobAsyncClient to construct a client that allows blob specific operations. Note, these types do not support client-side encryption, though decryption is possible in case the associated block/page/append blob contains encrypted data.

Please refer to the Azure Docs for more information.

Method Summary

Modifier and Type Method and Description
Flux<ByteBuffer> download()
Mono<BinaryData> downloadContent()
Mono<BlobDownloadContentAsyncResponse> downloadContentWithResponse(DownloadRetryOptions options, BlobRequestConditions requestConditions)
Flux<ByteBuffer> downloadStream()
Mono<BlobDownloadAsyncResponse> downloadStreamWithResponse(BlobRange range, DownloadRetryOptions options, BlobRequestConditions requestConditions, boolean getRangeContentMd5)
Mono<BlobProperties> downloadToFile(String filePath)
Mono<BlobProperties> downloadToFile(String filePath, boolean overwrite)
Mono<Response<BlobProperties>> downloadToFileWithResponse(BlobDownloadToFileOptions options)
Mono<Response<BlobProperties>> downloadToFileWithResponse(String filePath, BlobRange range, ParallelTransferOptions parallelTransferOptions, DownloadRetryOptions options, BlobRequestConditions requestConditions, boolean rangeGetContentMd5)
Mono<Response<BlobProperties>> downloadToFileWithResponse(String filePath, BlobRange range, ParallelTransferOptions parallelTransferOptions, DownloadRetryOptions options, BlobRequestConditions requestConditions, boolean rangeGetContentMd5, Set<OpenOption> openOptions)
Mono<BlobDownloadAsyncResponse> downloadWithResponse(BlobRange range, DownloadRetryOptions options, BlobRequestConditions requestConditions, boolean getRangeContentMd5)
EncryptedBlobAsyncClient getCustomerProvidedKeyAsyncClient(CustomerProvidedKey customerProvidedKey)

Creates a new EncryptedBlobAsyncClient with the specified customerProvidedKey.

EncryptedBlobAsyncClient getEncryptionScopeAsyncClient(String encryptionScope)

Creates a new EncryptedBlobAsyncClient with the specified encryptionScope.

Flux<ByteBuffer> query(String expression)

Unsupported.

Mono<BlobQueryAsyncResponse> queryWithResponse(BlobQueryOptions queryOptions)

Unsupported.

Mono<BlockBlobItem> upload(Flux<ByteBuffer> data, ParallelTransferOptions parallelTransferOptions)

Creates a new block blob.

Mono<BlockBlobItem> upload(Flux<ByteBuffer> data, ParallelTransferOptions parallelTransferOptions, boolean overwrite)

Creates a new block blob, or updates the content of an existing block blob.

Mono<Void> uploadFromFile(String filePath)

Creates a new block blob with the content of the specified file.

Mono<Void> uploadFromFile(String filePath, boolean overwrite)

Creates a new block blob, or updates the content of an existing block blob, with the content of the specified file.

Mono<Void> uploadFromFile(String filePath, ParallelTransferOptions parallelTransferOptions, BlobHttpHeaders headers, Map<String,String> metadata, AccessTier tier, BlobRequestConditions requestConditions)

Creates a new block blob, or updates the content of an existing block blob, with the content of the specified file.

Mono<Response<BlockBlobItem>> uploadFromFileWithResponse(BlobUploadFromFileOptions options)

Creates a new block blob, or updates the content of an existing block blob, with the content of the specified file.

Mono<Response<BlockBlobItem>> uploadWithResponse(BlobParallelUploadOptions options)

Creates a new block blob, or updates the content of an existing block blob.

Mono<Response<BlockBlobItem>> uploadWithResponse(Flux<ByteBuffer> data, ParallelTransferOptions parallelTransferOptions, BlobHttpHeaders headers, Map<String,String> metadata, AccessTier tier, BlobRequestConditions requestConditions)

Creates a new block blob, or updates the content of an existing block blob.

Methods inherited from BlobAsyncClient

Methods inherited from BlobAsyncClientBase

Methods inherited from java.lang.Object

Method Details

download

@Deprecated
public Flux download()

Overrides:

EncryptedBlobAsyncClient.download()

downloadContent

public Mono downloadContent()

Overrides:

EncryptedBlobAsyncClient.downloadContent()

downloadContentWithResponse

public Mono downloadContentWithResponse(DownloadRetryOptions options, BlobRequestConditions requestConditions)

Overrides:

EncryptedBlobAsyncClient.downloadContentWithResponse(DownloadRetryOptions options, BlobRequestConditions requestConditions)

Parameters:

options
requestConditions

downloadStream

public Flux downloadStream()

Overrides:

EncryptedBlobAsyncClient.downloadStream()

downloadStreamWithResponse

public Mono downloadStreamWithResponse(BlobRange range, DownloadRetryOptions options, BlobRequestConditions requestConditions, boolean getRangeContentMd5)

Overrides:

EncryptedBlobAsyncClient.downloadStreamWithResponse(BlobRange range, DownloadRetryOptions options, BlobRequestConditions requestConditions, boolean getRangeContentMd5)

Parameters:

range
options
requestConditions
getRangeContentMd5

downloadToFile

public Mono downloadToFile(String filePath)

Overrides:

EncryptedBlobAsyncClient.downloadToFile(String filePath)

Parameters:

filePath

downloadToFile

public Mono downloadToFile(String filePath, boolean overwrite)

Overrides:

EncryptedBlobAsyncClient.downloadToFile(String filePath, boolean overwrite)

Parameters:

filePath
overwrite

downloadToFileWithResponse

public Mono<>> downloadToFileWithResponse(BlobDownloadToFileOptions options)

Overrides:

EncryptedBlobAsyncClient.downloadToFileWithResponse(BlobDownloadToFileOptions options)

Parameters:

options

downloadToFileWithResponse

public Mono<>> downloadToFileWithResponse(String filePath, BlobRange range, ParallelTransferOptions parallelTransferOptions, DownloadRetryOptions options, BlobRequestConditions requestConditions, boolean rangeGetContentMd5)

Overrides:

EncryptedBlobAsyncClient.downloadToFileWithResponse(String filePath, BlobRange range, ParallelTransferOptions parallelTransferOptions, DownloadRetryOptions options, BlobRequestConditions requestConditions, boolean rangeGetContentMd5)

Parameters:

filePath
range
parallelTransferOptions
options
requestConditions
rangeGetContentMd5

downloadToFileWithResponse

public Mono<>> downloadToFileWithResponse(String filePath, BlobRange range, ParallelTransferOptions parallelTransferOptions, DownloadRetryOptions options, BlobRequestConditions requestConditions, boolean rangeGetContentMd5, Set openOptions)

Overrides:

EncryptedBlobAsyncClient.downloadToFileWithResponse(String filePath, BlobRange range, ParallelTransferOptions parallelTransferOptions, DownloadRetryOptions options, BlobRequestConditions requestConditions, boolean rangeGetContentMd5, Set<OpenOption> openOptions)

Parameters:

filePath
range
parallelTransferOptions
options
requestConditions
rangeGetContentMd5
openOptions

downloadWithResponse

@Deprecated
public Mono downloadWithResponse(BlobRange range, DownloadRetryOptions options, BlobRequestConditions requestConditions, boolean getRangeContentMd5)

Overrides:

EncryptedBlobAsyncClient.downloadWithResponse(BlobRange range, DownloadRetryOptions options, BlobRequestConditions requestConditions, boolean getRangeContentMd5)

Parameters:

range
options
requestConditions
getRangeContentMd5

getCustomerProvidedKeyAsyncClient

public EncryptedBlobAsyncClient getCustomerProvidedKeyAsyncClient(CustomerProvidedKey customerProvidedKey)

Creates a new EncryptedBlobAsyncClient with the specified customerProvidedKey.

Overrides:

EncryptedBlobAsyncClient.getCustomerProvidedKeyAsyncClient(CustomerProvidedKey customerProvidedKey)

Parameters:

customerProvidedKey - the CustomerProvidedKey for the blob, pass null to use no customer provided key.

Returns:

a EncryptedBlobAsyncClient with the specified customerProvidedKey.

getEncryptionScopeAsyncClient

public EncryptedBlobAsyncClient getEncryptionScopeAsyncClient(String encryptionScope)

Creates a new EncryptedBlobAsyncClient with the specified encryptionScope.

Overrides:

EncryptedBlobAsyncClient.getEncryptionScopeAsyncClient(String encryptionScope)

Parameters:

encryptionScope - the encryption scope for the blob, pass null to use no encryption scope.

Returns:

a EncryptedBlobAsyncClient with the specified encryptionScope.

query

public Flux query(String expression)

Unsupported. Cannot query data encrypted on client side.

Overrides:

EncryptedBlobAsyncClient.query(String expression)

Parameters:

expression

queryWithResponse

public Mono queryWithResponse(BlobQueryOptions queryOptions)

Unsupported. Cannot query data encrypted on client side.

Overrides:

EncryptedBlobAsyncClient.queryWithResponse(BlobQueryOptions queryOptions)

Parameters:

queryOptions

upload

public Mono upload(Flux data, ParallelTransferOptions parallelTransferOptions)

Creates a new block blob. By default, this method will not overwrite an existing blob.

Updating an existing block blob overwrites any existing blob metadata. Partial updates are not supported with this method; the content of the existing blob is overwritten with the new content. To perform a partial update of block blob's, use stageBlock and BlockBlobAsyncClient#commitBlockList(List) on a regular blob client. For more information, see the Azure Docs for Put Block and the Azure Docs for Put Block List.

The data passed need not support multiple subscriptions/be replayable as is required in other upload methods when retries are enabled, and the length of the data need not be known in advance. Therefore, this method should support uploading any arbitrary data source, including network streams. This behavior is possible because this method will perform some internal buffering as configured by the blockSize and numBuffers parameters, so while this method may offer additional convenience, it will not be as performant as other options, which should be preferred when possible.

Typically, the greater the number of buffers used, the greater the possible parallelism when transferring the data. Larger buffers means we will have to stage fewer blocks and therefore require fewer IO operations. The trade-offs between these values are context-dependent, so some experimentation may be required to optimize inputs for a given scenario.

Code Samples

ParallelTransferOptions parallelTransferOptions = new ParallelTransferOptions()
     .setBlockSizeLong(blockSize)
     .setMaxConcurrency(maxConcurrency);
 client.upload(data, parallelTransferOptions).subscribe(response ->
     System.out.printf("Uploaded BlockBlob MD5 is %s%n",
         Base64.getEncoder().encodeToString(response.getContentMd5())));

Overrides:

EncryptedBlobAsyncClient.upload(Flux<ByteBuffer> data, ParallelTransferOptions parallelTransferOptions)

Parameters:

data - The data to write to the blob. Unlike other upload methods, this method does not require that the Flux be replayable. In other words, it does not have to support multiple subscribers and is not expected to produce the same values across subscriptions.
parallelTransferOptions - ParallelTransferOptions used to configure buffered uploading.

Returns:

A reactive response containing the information of the uploaded block blob.

upload

public Mono upload(Flux data, ParallelTransferOptions parallelTransferOptions, boolean overwrite)

Creates a new block blob, or updates the content of an existing block blob.

Updating an existing block blob overwrites any existing blob metadata. Partial updates are not supported with this method; the content of the existing blob is overwritten with the new content. To perform a partial update of block blob's, use stageBlock and BlockBlobAsyncClient#commitBlockList(List) on a regular blob client. For more information, see the Azure Docs for Put Block and the Azure Docs for Put Block List.

The data passed need not support multiple subscriptions/be replayable as is required in other upload methods when retries are enabled, and the length of the data need not be known in advance. Therefore, this method should support uploading any arbitrary data source, including network streams. This behavior is possible because this method will perform some internal buffering as configured by the blockSize and numBuffers parameters, so while this method may offer additional convenience, it will not be as performant as other options, which should be preferred when possible.

Typically, the greater the number of buffers used, the greater the possible parallelism when transferring the data. Larger buffers means we will have to stage fewer blocks and therefore require fewer IO operations. The trade-offs between these values are context-dependent, so some experimentation may be required to optimize inputs for a given scenario.

Code Samples

ParallelTransferOptions parallelTransferOptions = new ParallelTransferOptions()
     .setBlockSizeLong(blockSize)
     .setMaxConcurrency(maxConcurrency);
 boolean overwrite = false; // Default behavior
 client.upload(data, parallelTransferOptions, overwrite).subscribe(response ->
     System.out.printf("Uploaded BlockBlob MD5 is %s%n",
         Base64.getEncoder().encodeToString(response.getContentMd5())));

Overrides:

EncryptedBlobAsyncClient.upload(Flux<ByteBuffer> data, ParallelTransferOptions parallelTransferOptions, boolean overwrite)

Parameters:

data - The data to write to the blob. Unlike other upload methods, this method does not require that the Flux be replayable. In other words, it does not have to support multiple subscribers and is not expected to produce the same values across subscriptions.
parallelTransferOptions - ParallelTransferOptions used to configure buffered uploading.
overwrite - Whether to overwrite if the blob exists.

Returns:

A reactive response containing the information of the uploaded block blob.

uploadFromFile

public Mono uploadFromFile(String filePath)

Creates a new block blob with the content of the specified file. By default, this method will not overwrite existing data

Code Samples

client.uploadFromFile(filePath)
     .doOnError(throwable -> System.err.printf("Failed to upload from file %s%n", throwable.getMessage()))
     .subscribe(completion -> System.out.println("Upload from file succeeded"));

Overrides:

EncryptedBlobAsyncClient.uploadFromFile(String filePath)

Parameters:

filePath - Path to the upload file

Returns:

An empty response

uploadFromFile

public Mono uploadFromFile(String filePath, boolean overwrite)

Creates a new block blob, or updates the content of an existing block blob, with the content of the specified file.

Code Samples

boolean overwrite = false; // Default behavior
 client.uploadFromFile(filePath, overwrite)
     .doOnError(throwable -> System.err.printf("Failed to upload from file %s%n", throwable.getMessage()))
     .subscribe(completion -> System.out.println("Upload from file succeeded"));

Overrides:

EncryptedBlobAsyncClient.uploadFromFile(String filePath, boolean overwrite)

Parameters:

filePath - Path to the upload file
overwrite - Whether to overwrite should the blob exist.

Returns:

An empty response

uploadFromFile

public Mono uploadFromFile(String filePath, ParallelTransferOptions parallelTransferOptions, BlobHttpHeaders headers, Map metadata, AccessTier tier, BlobRequestConditions requestConditions)

Creates a new block blob, or updates the content of an existing block blob, with the content of the specified file.

Code Samples

BlobHttpHeaders headers = new BlobHttpHeaders()
     .setContentMd5("data".getBytes(StandardCharsets.UTF_8))
     .setContentLanguage("en-US")
     .setContentType("binary");

 Map<String, String> metadata = new HashMap<>(Collections.singletonMap("metadata", "value"));
 BlobRequestConditions requestConditions = new BlobRequestConditions()
     .setLeaseId(leaseId)
     .setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));

 ParallelTransferOptions parallelTransferOptions = new ParallelTransferOptions()
     .setBlockSizeLong(blockSize);

 client.uploadFromFile(filePath, parallelTransferOptions, headers, metadata, AccessTier.HOT, requestConditions)
     .doOnError(throwable -> System.err.printf("Failed to upload from file %s%n", throwable.getMessage()))
     .subscribe(completion -> System.out.println("Upload from file succeeded"));

Overrides:

EncryptedBlobAsyncClient.uploadFromFile(String filePath, ParallelTransferOptions parallelTransferOptions, BlobHttpHeaders headers, Map<String,String> metadata, AccessTier tier, BlobRequestConditions requestConditions)

Parameters:

filePath - Path to the upload file
parallelTransferOptions - ParallelTransferOptions to use to upload from file.
headers - BlobHttpHeaders
metadata - Metadata to associate with the blob. If there is leading or trailing whitespace in any metadata key or value, it must be removed or encoded.
tier - AccessTier for the destination blob.
requestConditions - BlobRequestConditions

Returns:

An empty response

uploadFromFileWithResponse

public Mono<>> uploadFromFileWithResponse(BlobUploadFromFileOptions options)

Creates a new block blob, or updates the content of an existing block blob, with the content of the specified file.

Code Samples

BlobHttpHeaders headers = new BlobHttpHeaders()
     .setContentMd5("data".getBytes(StandardCharsets.UTF_8))
     .setContentLanguage("en-US")
     .setContentType("binary");

 Map<String, String> metadata = new HashMap<>(Collections.singletonMap("metadata", "value"));
 Map<String, String> tags = new HashMap<>(Collections.singletonMap("tag", "value"));
 BlobRequestConditions requestConditions = new BlobRequestConditions()
     .setLeaseId(leaseId)
     .setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));

 ParallelTransferOptions parallelTransferOptions = new ParallelTransferOptions()
     .setBlockSizeLong(blockSize);

 client.uploadFromFileWithResponse(new BlobUploadFromFileOptions(filePath)
     .setParallelTransferOptions(parallelTransferOptions).setHeaders(headers).setMetadata(metadata).setTags(tags)
     .setTier(AccessTier.HOT).setRequestConditions(requestConditions))
     .doOnError(throwable -> System.err.printf("Failed to upload from file %s%n", throwable.getMessage()))
     .subscribe(completion -> System.out.println("Upload from file succeeded"));

Overrides:

EncryptedBlobAsyncClient.uploadFromFileWithResponse(BlobUploadFromFileOptions options)

Parameters:

Returns:

A reactive response containing the information of the uploaded block blob.

uploadWithResponse

public Mono<>> uploadWithResponse(BlobParallelUploadOptions options)

Creates a new block blob, or updates the content of an existing block blob. Updating an existing block blob overwrites any existing blob metadata. Partial updates are not supported with this method; the content of the existing blob is overwritten with the new content. To perform a partial update of a block blob's, use stageBlock and BlockBlobAsyncClient#commitBlockList(List), which this method uses internally. For more information, see the Azure Docs for Put Block and the Azure Docs for Put Block List.

The data passed need not support multiple subscriptions/be replayable as is required in other upload methods when retries are enabled, and the length of the data need not be known in advance. Therefore, this method should support uploading any arbitrary data source, including network streams. This behavior is possible because this method will perform some internal buffering as configured by the blockSize and numBuffers parameters, so while this method may offer additional convenience, it will not be as performant as other options, which should be preferred when possible.

Typically, the greater the number of buffers used, the greater the possible parallelism when transferring the data. Larger buffers means we will have to stage fewer blocks and therefore require fewer IO operations. The trade-offs between these values are context-dependent, so some experimentation may be required to optimize inputs for a given scenario.

Code Samples

BlobHttpHeaders headers = new BlobHttpHeaders()
     .setContentMd5("data".getBytes(StandardCharsets.UTF_8))
     .setContentLanguage("en-US")
     .setContentType("binary");

 Map<String, String> metadata = new HashMap<>(Collections.singletonMap("metadata", "value"));
 Map<String, String> tags = new HashMap<>(Collections.singletonMap("tag", "value"));
 BlobRequestConditions requestConditions = new BlobRequestConditions()
     .setLeaseId(leaseId)
     .setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
 ParallelTransferOptions parallelTransferOptions = new ParallelTransferOptions()
     .setBlockSizeLong(blockSize)
     .setMaxConcurrency(maxConcurrency);

 client.uploadWithResponse(new BlobParallelUploadOptions(data)
     .setParallelTransferOptions(parallelTransferOptions).setHeaders(headers).setMetadata(metadata)
     .setTags(tags).setTier(AccessTier.HOT).setRequestConditions(requestConditions))
     .subscribe(response -> System.out.printf("Uploaded BlockBlob MD5 is %s%n",
         Base64.getEncoder().encodeToString(response.getValue().getContentMd5())));

Flux be replayable. In other words, it does not have to support multiple subscribers and is not expected to produce the same values across subscriptions.

Overrides:

EncryptedBlobAsyncClient.uploadWithResponse(BlobParallelUploadOptions options)

Parameters:

Returns:

A reactive response containing the information of the uploaded block blob.

uploadWithResponse

public Mono<>> uploadWithResponse(Flux data, ParallelTransferOptions parallelTransferOptions, BlobHttpHeaders headers, Map metadata, AccessTier tier, BlobRequestConditions requestConditions)

Creates a new block blob, or updates the content of an existing block blob. Updating an existing block blob overwrites any existing blob metadata. Partial updates are not supported with this method; the content of the existing blob is overwritten with the new content. To perform a partial update of a block blob's, use stageBlock and BlockBlobAsyncClient#commitBlockList(List), which this method uses internally. For more information, see the Azure Docs for Put Block and the Azure Docs for Put Block List.

The data passed need not support multiple subscriptions/be replayable as is required in other upload methods when retries are enabled, and the length of the data need not be known in advance. Therefore, this method should support uploading any arbitrary data source, including network streams. This behavior is possible because this method will perform some internal buffering as configured by the blockSize and numBuffers parameters, so while this method may offer additional convenience, it will not be as performant as other options, which should be preferred when possible.

Typically, the greater the number of buffers used, the greater the possible parallelism when transferring the data. Larger buffers means we will have to stage fewer blocks and therefore require fewer IO operations. The trade-offs between these values are context-dependent, so some experimentation may be required to optimize inputs for a given scenario.

Code Samples

BlobHttpHeaders headers = new BlobHttpHeaders()
     .setContentMd5("data".getBytes(StandardCharsets.UTF_8))
     .setContentLanguage("en-US")
     .setContentType("binary");

 Map<String, String> metadata = new HashMap<>(Collections.singletonMap("metadata", "value"));
 BlobRequestConditions requestConditions = new BlobRequestConditions()
     .setLeaseId(leaseId)
     .setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
 ParallelTransferOptions parallelTransferOptions = new ParallelTransferOptions()
     .setBlockSizeLong(blockSize)
     .setMaxConcurrency(maxConcurrency);

 client.uploadWithResponse(data, parallelTransferOptions, headers, metadata, AccessTier.HOT, requestConditions)
     .subscribe(response -> System.out.printf("Uploaded BlockBlob MD5 is %s%n",
         Base64.getEncoder().encodeToString(response.getValue().getContentMd5())));

Overrides:

EncryptedBlobAsyncClient.uploadWithResponse(Flux<ByteBuffer> data, ParallelTransferOptions parallelTransferOptions, BlobHttpHeaders headers, Map<String,String> metadata, AccessTier tier, BlobRequestConditions requestConditions)

Parameters:

data - The data to write to the blob. Unlike other upload methods, this method does not require that the Flux be replayable. In other words, it does not have to support multiple subscribers and is not expected to produce the same values across subscriptions.
parallelTransferOptions - ParallelTransferOptions used to configure buffered uploading.
headers - BlobHttpHeaders
metadata - Metadata to associate with the blob. If there is leading or trailing whitespace in any metadata key or value, it must be removed or encoded.
tier - AccessTier for the destination blob.
requestConditions - BlobRequestConditions

Returns:

A reactive response containing the information of the uploaded block blob.

Applies to