BlockBlobAsyncClient Class
- java.
lang. Object - com.
azure. storage. blob. specialized. BlobAsyncClientBase - com.
azure. storage. blob. specialized. BlockBlobAsyncClient
- com.
- com.
public final class BlockBlobAsyncClient
extends BlobAsyncClientBase
Client to a block blob. It may only be instantiated through a SpecializedBlobClientBuilder or via the method getBlockBlobAsyncClient(). This class does not hold any state about a particular blob, but is instead a convenient way of sending appropriate requests to the resource on the service.
Please refer to the Azure Docs for more information.
Note this client is an async client that returns reactive responses from Spring Reactor Core project (https://projectreactor.io/). Calling the methods in this client will NOT start the actual network operation, until .subscribe()
is called on the reactive response. You can simply convert one of these responses to a CompletableFuture object through Mono#toFuture().
Field Summary
Modifier and Type | Field and Description |
---|---|
static final int |
MAX_BLOCKS
Indicates the maximum number of blocks allowed in a block blob. |
static final int |
MAX_STAGE_BLOCK_BYTES
Deprecated Indicates the maximum number of bytes that can be sent in a call to stage |
static final long |
MAX_STAGE_BLOCK_BYTES_LONG
Indicates the maximum number of bytes that can be sent in a call to stage |
static final int |
MAX_UPLOAD_BLOB_BYTES
Deprecated Indicates the maximum number of bytes that can be sent in a call to upload. |
static final long |
MAX_UPLOAD_BLOB_BYTES_LONG
Indicates the maximum number of bytes that can be sent in a call to upload. |
Method Summary
Methods inherited from BlobAsyncClientBase
Methods inherited from java.lang.Object
Field Details
MAX_BLOCKS
public static final int MAX_BLOCKS
Indicates the maximum number of blocks allowed in a block blob.
MAX_STAGE_BLOCK_BYTES
@Deprecated
public static final int MAX_STAGE_BLOCK_BYTES
Deprecated
Indicates the maximum number of bytes that can be sent in a call to stageBlock.
MAX_STAGE_BLOCK_BYTES_LONG
public static final long MAX_STAGE_BLOCK_BYTES_LONG
Indicates the maximum number of bytes that can be sent in a call to stageBlock.
MAX_UPLOAD_BLOB_BYTES
@Deprecated
public static final int MAX_UPLOAD_BLOB_BYTES
Deprecated
Indicates the maximum number of bytes that can be sent in a call to upload.
MAX_UPLOAD_BLOB_BYTES_LONG
public static final long MAX_UPLOAD_BLOB_BYTES_LONG
Indicates the maximum number of bytes that can be sent in a call to upload.
Method Details
commitBlockList
public Mono
Writes a blob by specifying the list of block IDs that are to make up the blob. In order to be written as part of a blob, a block must have been successfully written to the server in a prior stageBlock operation. You can call commitBlockList to update a blob by uploading only those blocks that have changed, then committing the new and existing blocks together. Any blocks not specified in the block list and permanently deleted. For more information, see the Azure Docs.
Code Samples
client.commitBlockList(Collections.singletonList(base64BlockID)).subscribe(response ->
System.out.printf("Committing block list completed. Last modified: %s%n", response.getLastModified()));
Parameters:
String
s that specifies the block IDs to be committed.
Returns:
commitBlockList
public Mono
Writes a blob by specifying the list of block IDs that are to make up the blob. In order to be written as part of a blob, a block must have been successfully written to the server in a prior stageBlock operation. You can call commitBlockList to update a blob by uploading only those blocks that have changed, then committing the new and existing blocks together. Any blocks not specified in the block list and permanently deleted. For more information, see the Azure Docs.
Code Samples
boolean overwrite = false; // Default behavior
client.commitBlockList(Collections.singletonList(base64BlockID), overwrite).subscribe(response ->
System.out.printf("Committing block list completed. Last modified: %s%n", response.getLastModified()));
Parameters:
String
s that specifies the block IDs to be committed.
Returns:
commitBlockListWithResponse
public Mono
Writes a blob by specifying the list of block IDs that are to make up the blob. In order to be written as part of a blob, a block must have been successfully written to the server in a prior stageBlock operation. You can call commitBlockList to update a blob by uploading only those blocks that have changed, then committing the new and existing blocks together. Any blocks not specified in the block list and permanently deleted. For more information, see the Azure Docs.
To avoid overwriting, pass "*" to setIfNoneMatch(String ifNoneMatch).
Code Samples
BlobHttpHeaders headers = new BlobHttpHeaders()
.setContentMd5("data".getBytes(StandardCharsets.UTF_8))
.setContentLanguage("en-US")
.setContentType("binary");
Map<String, String> metadata = Collections.singletonMap("metadata", "value");
Map<String, String> tags = Collections.singletonMap("tag", "value");
BlobRequestConditions requestConditions = new BlobRequestConditions()
.setLeaseId(leaseId)
.setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
client.commitBlockListWithResponse(new BlockBlobCommitBlockListOptions(Collections.singletonList(base64BlockID))
.setHeaders(headers).setMetadata(metadata).setTags(tags).setTier(AccessTier.HOT)
.setRequestConditions(requestConditions))
.subscribe(response ->
System.out.printf("Committing block list completed with status %d%n", response.getStatusCode()));
Parameters:
Returns:
commitBlockListWithResponse
public Mono
Writes a blob by specifying the list of block IDs that are to make up the blob. In order to be written as part of a blob, a block must have been successfully written to the server in a prior stageBlock operation. You can call commitBlockList to update a blob by uploading only those blocks that have changed, then committing the new and existing blocks together. Any blocks not specified in the block list and permanently deleted. For more information, see the Azure Docs.
To avoid overwriting, pass "*" to setIfNoneMatch(String ifNoneMatch).
Code Samples
BlobHttpHeaders headers = new BlobHttpHeaders()
.setContentMd5("data".getBytes(StandardCharsets.UTF_8))
.setContentLanguage("en-US")
.setContentType("binary");
Map<String, String> metadata = Collections.singletonMap("metadata", "value");
BlobRequestConditions requestConditions = new BlobRequestConditions()
.setLeaseId(leaseId)
.setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
client.commitBlockListWithResponse(Collections.singletonList(base64BlockID), headers, metadata,
AccessTier.HOT, requestConditions).subscribe(response ->
System.out.printf("Committing block list completed with status %d%n", response.getStatusCode()));
Parameters:
String
s that specifies the block IDs to be committed.
Returns:
getCustomerProvidedKeyAsyncClient
public BlockBlobAsyncClient getCustomerProvidedKeyAsyncClient(CustomerProvidedKey customerProvidedKey)
Creates a new BlockBlobAsyncClient with the specified customerProvidedKey
.
Overrides:
BlockBlobAsyncClient.getCustomerProvidedKeyAsyncClient(CustomerProvidedKey customerProvidedKey)Parameters:
null
to use no customer provided key.
Returns:
customerProvidedKey
.getEncryptionScopeAsyncClient
public BlockBlobAsyncClient getEncryptionScopeAsyncClient(String encryptionScope)
Creates a new BlockBlobAsyncClient with the specified encryptionScope
.
Overrides:
BlockBlobAsyncClient.getEncryptionScopeAsyncClient(String encryptionScope)Parameters:
null
to use no encryption scope.
Returns:
encryptionScope
.listBlocks
public Mono
Returns the list of blocks that have been uploaded as part of a block blob using the specified block list filter. For more information, see the Azure Docs.
Code Samples
client.listBlocks(BlockListType.ALL).subscribe(block -> {
System.out.println("Committed Blocks:");
block.getCommittedBlocks().forEach(b -> System.out.printf("Name: %s, Size: %d", b.getName(), b.getSizeLong()));
System.out.println("Uncommitted Blocks:");
block.getUncommittedBlocks().forEach(b -> System.out.printf("Name: %s, Size: %d", b.getName(), b.getSizeLong()));
});
Parameters:
Returns:
listBlocksWithResponse
public Mono
Returns the list of blocks that have been uploaded as part of a block blob using the specified block list filter. For more information, see the Azure Docs.
Code Samples
client.listBlocksWithResponse(BlockListType.ALL, leaseId).subscribe(response -> {
BlockList block = response.getValue();
System.out.println("Committed Blocks:");
block.getCommittedBlocks().forEach(b -> System.out.printf("Name: %s, Size: %d", b.getName(), b.getSizeLong()));
System.out.println("Uncommitted Blocks:");
block.getUncommittedBlocks().forEach(b -> System.out.printf("Name: %s, Size: %d", b.getName(), b.getSizeLong()));
});
Parameters:
Returns:
listBlocksWithResponse
public Mono
Returns the list of blocks that have been uploaded as part of a block blob using the specified block list filter. For more information, see the Azure Docs.
Code Samples
client.listBlocksWithResponse(new BlockBlobListBlocksOptions(BlockListType.ALL)
.setLeaseId(leaseId)
.setIfTagsMatch(tags)).subscribe(response -> {
BlockList block = response.getValue();
System.out.println("Committed Blocks:");
block.getCommittedBlocks().forEach(b -> System.out.printf("Name: %s, Size: %d", b.getName(),
b.getSizeLong()));
System.out.println("Uncommitted Blocks:");
block.getUncommittedBlocks().forEach(b -> System.out.printf("Name: %s, Size: %d", b.getName(),
b.getSizeLong()));
});
Parameters:
Returns:
stageBlock
public Mono
Uploads the specified block to the block blob's "staging area" to be later committed by a call to commitBlockList. For more information, see the Azure Docs.
Note that the data passed must be replayable if retries are enabled (the default), see BinaryData#isReplayable().
Parameters:
String
that specifies the ID for this block. Note that all block
ids for a given blob must be the same length.
BinaryData
must have defined length
and must be replayable if retries are enabled (the default), see BinaryData#isReplayable().
Returns:
BinaryData.fromFlux(data, length, false) .flatMap(binaryData -> client.stageBlock(base64BlockID, binaryData)) .subscribe( response -> System.out.println("Staging block completed"), error -> System.out.printf("Error when calling stage Block: %s", error));
stageBlock
public Mono
Uploads the specified block to the block blob's "staging area" to be later committed by a call to commitBlockList. For more information, see the Azure Docs.
Note that the data passed must be replayable if retries are enabled (the default). In other words, the Flux
must produce the same data each time it is subscribed to.
Parameters:
String
that specifies the ID for this block. Note that all block
ids for a given blob must be the same length.
Flux
must be replayable if retries are enabled
(the default). In other words, the Flux
must produce the same data each time it is subscribed to.
Flux
.
Returns:
client.stageBlock(base64BlockID, data, length) .subscribe( response -> System.out.println("Staging block completed"), error -> System.out.printf("Error when calling stage Block: %s", error));
stageBlockFromUrl
public Mono
Creates a new block to be committed as part of a blob where the contents are read from a URL. For more information, see the Azure Docs.
Code Samples
client.stageBlockFromUrl(base64BlockID, sourceUrl, new BlobRange(offset, count))
.subscribe(
response -> System.out.println("Staging block completed"),
error -> System.out.printf("Error when calling stage Block: %s", error));
Parameters:
String
that specifies the ID for this block. Note that all block
ids for a given blob must be the same length.
Returns:
stageBlockFromUrlWithResponse
public Mono
Creates a new block to be committed as part of a blob where the contents are read from a URL. For more information, see the Azure Docs.
Code Samples
BlobRequestConditions sourceRequestConditions = new BlobRequestConditions()
.setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
client.stageBlockFromUrlWithResponse(new BlockBlobStageBlockFromUrlOptions(base64BlockID, sourceUrl)
.setSourceRange(new BlobRange(offset, count)).setLeaseId(leaseId)
.setSourceRequestConditions(sourceRequestConditions)).subscribe(response ->
System.out.printf("Staging block from URL completed with status %d%n", response.getStatusCode()));
Parameters:
Returns:
stageBlockFromUrlWithResponse
public Mono
Creates a new block to be committed as part of a blob where the contents are read from a URL. For more information, see the Azure Docs.
Code Samples
BlobRequestConditions sourceRequestConditions = new BlobRequestConditions()
.setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
client.stageBlockFromUrlWithResponse(base64BlockID, sourceUrl, new BlobRange(offset, count), null,
leaseId, sourceRequestConditions).subscribe(response ->
System.out.printf("Staging block from URL completed with status %d%n", response.getStatusCode()));
Parameters:
String
that specifies the ID for this block. Note that all block
ids for a given blob must be the same length.
Returns:
stageBlockWithResponse
public Mono
Uploads the specified block to the block blob's "staging area" to be later committed by a call to commitBlockList. For more information, see the Azure Docs.
Note that the data passed must be replayable if retries are enabled (the default), see BinaryData#isReplayable().
Code Samples
BinaryData.fromFlux(data, length, false)
.flatMap(binaryData -> client.stageBlockWithResponse(
new BlockBlobStageBlockOptions(base64BlockID, binaryData)
.setContentMd5(md5)
.setLeaseId(leaseId)))
.subscribe(response ->
System.out.printf("Staging block completed with status %d%n", response.getStatusCode()));
Parameters:
Returns:
stageBlockWithResponse
public Mono
Uploads the specified block to the block blob's "staging area" to be later committed by a call to commitBlockList. For more information, see the Azure Docs.
Note that the data passed must be replayable if retries are enabled (the default). In other words, the Flux
must produce the same data each time it is subscribed to.
Code Samples
client.stageBlockWithResponse(base64BlockID, data, length, md5, leaseId).subscribe(response ->
System.out.printf("Staging block completed with status %d%n", response.getStatusCode()));
Parameters:
String
that specifies the ID for this block. Note that all block
ids for a given blob must be the same length.
Flux
must be replayable if retries are enabled
(the default). In other words, the Flux must produce the same data each time it is subscribed to.
Flux
.
Returns:
upload
public Mono
Creates a new block blob. By default, this method will not overwrite an existing blob. Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not supported with PutBlob; the content of the existing blob is overwritten with the new content. To perform a partial update of a block blob's, use PutBlock and PutBlockList. For more information, see the Azure Docs.
Note that the data passed must be replayable if retries are enabled (the default). In other words, the Flux
must produce the same data each time it is subscribed to.
Code Samples
BinaryData.fromFlux(data, length, false)
.flatMap(binaryData -> client.upload(binaryData))
.subscribe(response ->
System.out.printf("Uploaded BlockBlob MD5 is %s%n",
Base64.getEncoder().encodeToString(response.getContentMd5())));
Parameters:
BinaryData
must have defined length
and must be replayable if retries are enabled (the default), see BinaryData#isReplayable().
Returns:
upload
public Mono
Creates a new block blob, or updates the content of an existing block blob. Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not supported with PutBlob; the content of the existing blob is overwritten with the new content. To perform a partial update of a block blob's, use PutBlock and PutBlockList. For more information, see the Azure Docs.
Note that the data passed must be replayable if retries are enabled (the default). In other words, the Flux
must produce the same data each time it is subscribed to.
Code Samples
boolean overwrite = false; // Default behavior
BinaryData.fromFlux(data, length, false)
.flatMap(binaryData -> client.upload(binaryData, overwrite))
.subscribe(response ->
System.out.printf("Uploaded BlockBlob MD5 is %s%n",
Base64.getEncoder().encodeToString(response.getContentMd5())));
Parameters:
BinaryData
must have defined length
and must be replayable if retries are enabled (the default), see BinaryData#isReplayable().
Returns:
upload
public Mono
Creates a new block blob. By default, this method will not overwrite an existing blob. Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not supported with PutBlob; the content of the existing blob is overwritten with the new content. To perform a partial update of a block blob's, use PutBlock and PutBlockList. For more information, see the Azure Docs.
Note that the data passed must be replayable if retries are enabled (the default). In other words, the Flux
must produce the same data each time it is subscribed to.
Code Samples
client.upload(data, length).subscribe(response ->
System.out.printf("Uploaded BlockBlob MD5 is %s%n",
Base64.getEncoder().encodeToString(response.getContentMd5())));
Parameters:
Flux
must be replayable if retries are enabled
(the default). In other words, the Flux must produce the same data each time it is subscribed to.
Flux
.
Returns:
upload
public Mono
Creates a new block blob, or updates the content of an existing block blob. Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not supported with PutBlob; the content of the existing blob is overwritten with the new content. To perform a partial update of a block blob's, use PutBlock and PutBlockList. For more information, see the Azure Docs.
Note that the data passed must be replayable if retries are enabled (the default). In other words, the Flux
must produce the same data each time it is subscribed to.
Code Samples
boolean overwrite = false; // Default behavior
client.upload(data, length, overwrite).subscribe(response ->
System.out.printf("Uploaded BlockBlob MD5 is %s%n",
Base64.getEncoder().encodeToString(response.getContentMd5())));
Parameters:
Flux
must be replayable if retries are enabled
(the default). In other words, the Flux must produce the same data each time it is subscribed to.
Flux
.
Returns:
uploadFromUrl
public Mono
Creates a new block blob, or updates the content of an existing block blob.
Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not supported with PutBlobFromUrl; the content of the existing blob is overwritten with the new content. For more information, see the Azure Docs.
Code Samples
client.uploadFromUrl(sourceUrl)
.subscribe(response ->
System.out.printf("Uploaded BlockBlob from URL, MD5 is %s%n",
Base64.getEncoder().encodeToString(response.getContentMd5())));
Parameters:
Returns:
uploadFromUrl
public Mono
Creates a new block blob, or updates the content of an existing block blob.
Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not supported with PutBlobFromUrl; the content of the existing blob is overwritten with the new content. For more information, see the Azure Docs.
Code Samples
boolean overwrite = false; // Default behavior
client.uploadFromUrl(sourceUrl, overwrite).subscribe(response ->
System.out.printf("Uploaded BlockBlob from URL, MD5 is %s%n",
Base64.getEncoder().encodeToString(response.getContentMd5())));
Parameters:
Returns:
uploadFromUrlWithResponse
public Mono
Creates a new block blob, or updates the content of an existing block blob.
Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not supported with PutBlobFromUrl; the content of the existing blob is overwritten with the new content. For more information, see the Azure Docs.
To avoid overwriting, pass "*" to setIfNoneMatch(String ifNoneMatch).
Code Samples
BlobHttpHeaders headers = new BlobHttpHeaders()
.setContentMd5("data".getBytes(StandardCharsets.UTF_8))
.setContentLanguage("en-US")
.setContentType("binary");
Map<String, String> metadata = Collections.singletonMap("metadata", "value");
Map<String, String> tags = Collections.singletonMap("tag", "value");
byte[] md5 = MessageDigest.getInstance("MD5").digest("data".getBytes(StandardCharsets.UTF_8));
BlobRequestConditions requestConditions = new BlobRequestConditions()
.setLeaseId(leaseId)
.setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
client.uploadFromUrlWithResponse(new BlobUploadFromUrlOptions(sourceUrl).setHeaders(headers)
.setTags(tags).setTier(AccessTier.HOT).setContentMd5(md5)
.setDestinationRequestConditions(requestConditions))
.subscribe(response -> System.out.printf("Uploaded BlockBlob from URL, MD5 is %s%n",
Base64.getEncoder().encodeToString(response.getValue().getContentMd5())));
Parameters:
Returns:
uploadWithResponse
public Mono
Creates a new block blob, or updates the content of an existing block blob.
Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not supported with PutBlob; the content of the existing blob is overwritten with the new content. To perform a partial update of a block blob's, use PutBlock and PutBlockList. For more information, see the Azure Docs.
Note that the data passed must be replayable if retries are enabled (the default). In other words, the Flux
must produce the same data each time it is subscribed to.
To avoid overwriting, pass "*" to setIfNoneMatch(String ifNoneMatch).
Code Samples
BlobHttpHeaders headers = new BlobHttpHeaders()
.setContentMd5("data".getBytes(StandardCharsets.UTF_8))
.setContentLanguage("en-US")
.setContentType("binary");
Map<String, String> metadata = Collections.singletonMap("metadata", "value");
Map<String, String> tags = Collections.singletonMap("tag", "value");
byte[] md5 = MessageDigest.getInstance("MD5").digest("data".getBytes(StandardCharsets.UTF_8));
BlobRequestConditions requestConditions = new BlobRequestConditions()
.setLeaseId(leaseId)
.setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
client.uploadWithResponse(new BlockBlobSimpleUploadOptions(data, length).setHeaders(headers)
.setMetadata(metadata).setTags(tags).setTier(AccessTier.HOT).setContentMd5(md5)
.setRequestConditions(requestConditions))
.subscribe(response -> System.out.printf("Uploaded BlockBlob MD5 is %s%n",
Base64.getEncoder().encodeToString(response.getValue().getContentMd5())));
Parameters:
Returns:
uploadWithResponse
public Mono
Creates a new block blob, or updates the content of an existing block blob.
Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not supported with PutBlob; the content of the existing blob is overwritten with the new content. To perform a partial update of a block blob's, use PutBlock and PutBlockList. For more information, see the Azure Docs.
Note that the data passed must be replayable if retries are enabled (the default). In other words, the Flux
must produce the same data each time it is subscribed to.
To avoid overwriting, pass "*" to setIfNoneMatch(String ifNoneMatch).
Code Samples
BlobHttpHeaders headers = new BlobHttpHeaders()
.setContentMd5("data".getBytes(StandardCharsets.UTF_8))
.setContentLanguage("en-US")
.setContentType("binary");
Map<String, String> metadata = Collections.singletonMap("metadata", "value");
byte[] md5 = MessageDigest.getInstance("MD5").digest("data".getBytes(StandardCharsets.UTF_8));
BlobRequestConditions requestConditions = new BlobRequestConditions()
.setLeaseId(leaseId)
.setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
client.uploadWithResponse(data, length, headers, metadata, AccessTier.HOT, md5, requestConditions)
.subscribe(response -> System.out.printf("Uploaded BlockBlob MD5 is %s%n",
Base64.getEncoder().encodeToString(response.getValue().getContentMd5())));
Parameters:
Flux
must be replayable if retries are enabled
(the default). In other words, the Flux must produce the same data each time it is subscribed to.
Flux
.
Returns:
Applies to
Azure SDK for Java