public final class BlockBlobAsyncClient extends BlobAsyncClientBase
SpecializedBlobClientBuilder
or via the method
BlobAsyncClient.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()
.
Modifier and Type | Field and Description |
---|---|
static int |
MAX_BLOCKS
Indicates the maximum number of blocks allowed in a block blob.
|
static int |
MAX_STAGE_BLOCK_BYTES
Indicates the maximum number of bytes that can be sent in a call to stageBlock.
|
static int |
MAX_UPLOAD_BLOB_BYTES
Indicates the maximum number of bytes that can be sent in a call to upload.
|
accountName, azureBlobStorage, blobName, containerName, serviceVersion
Modifier and Type | Method and Description |
---|---|
Mono<BlockBlobItem> |
commitBlockList(List<String> base64BlockIds)
Writes a blob by specifying the list of block IDs that are to make up the blob.
|
Mono<Response<BlockBlobItem>> |
commitBlockListWithResponse(List<String> base64BlockIds,
BlobHttpHeaders headers,
Map<String,String> metadata,
AccessTier tier,
BlobRequestConditions requestConditions)
Writes a blob by specifying the list of block IDs that are to make up the blob.
|
Mono<BlockList> |
listBlocks(BlockListType listType)
Returns the list of blocks that have been uploaded as part of a block blob using the specified block list filter.
|
Mono<Response<BlockList>> |
listBlocksWithResponse(BlockListType listType,
String leaseId)
Returns the list of blocks that have been uploaded as part of a block blob using the specified block list
filter.
|
Mono<Void> |
stageBlock(String base64BlockId,
Flux<ByteBuffer> data,
long length)
Uploads the specified block to the block blob's "staging area" to be later committed by a call to
commitBlockList.
|
Mono<Void> |
stageBlockFromUrl(String base64BlockId,
String sourceUrl,
BlobRange sourceRange)
Creates a new block to be committed as part of a blob where the contents are read from a URL.
|
Mono<Response<Void>> |
stageBlockFromUrlWithResponse(String base64BlockId,
String sourceUrl,
BlobRange sourceRange,
byte[] sourceContentMd5,
String leaseId,
BlobRequestConditions sourceRequestConditions)
Creates a new block to be committed as part of a blob where the contents are read from a URL.
|
Mono<Response<Void>> |
stageBlockWithResponse(String base64BlockId,
Flux<ByteBuffer> data,
long length,
byte[] contentMd5,
String leaseId)
Uploads the specified block to the block blob's "staging area" to be later committed by a call to
commitBlockList.
|
Mono<BlockBlobItem> |
upload(Flux<ByteBuffer> data,
long length)
Creates a new block blob.
|
Mono<BlockBlobItem> |
upload(Flux<ByteBuffer> data,
long length,
boolean overwrite)
Creates a new block blob, or updates the content of an existing block blob.
|
Mono<Response<BlockBlobItem>> |
uploadWithResponse(Flux<ByteBuffer> data,
long length,
BlobHttpHeaders headers,
Map<String,String> metadata,
AccessTier tier,
byte[] contentMd5,
BlobRequestConditions requestConditions)
Creates a new block blob, or updates the content of an existing block blob.
|
abortCopyFromUrl, abortCopyFromUrlWithResponse, beginCopy, beginCopy, copyFromUrl, copyFromUrlWithResponse, createSnapshot, createSnapshotWithResponse, delete, deleteWithResponse, download, downloadToFile, downloadToFileWithResponse, downloadWithResponse, exists, existsWithResponse, getAccountInfo, getAccountInfoWithResponse, getAccountName, getBlobName, getBlobUrl, getContainerName, getCustomerProvidedKey, getHttpPipeline, getProperties, getPropertiesWithResponse, getServiceVersion, getSnapshotClient, getSnapshotId, isSnapshot, setAccessTier, setAccessTierWithResponse, setHttpHeaders, setHttpHeadersWithResponse, setMetadata, setMetadataWithResponse, undelete, undeleteWithResponse
public static final int MAX_UPLOAD_BLOB_BYTES
public static final int MAX_STAGE_BLOCK_BYTES
public static final int MAX_BLOCKS
public Mono<BlockBlobItem> upload(Flux<ByteBuffer> data, long length)
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())));
data
- The data to write to the blob. Note that this 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.length
- The exact length of the data. It is important that this value match precisely the length of the
data emitted by the Flux
.public Mono<BlockBlobItem> upload(Flux<ByteBuffer> data, long length, boolean overwrite)
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())));
data
- The data to write to the blob. Note that this 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.length
- The exact length of the data. It is important that this value match precisely the length of the
data emitted by the Flux
.overwrite
- Whether or not to overwrite, should data exist on the blob.public Mono<Response<BlockBlobItem>> uploadWithResponse(Flux<ByteBuffer> data, long length, BlobHttpHeaders headers, Map<String,String> metadata, AccessTier tier, byte[] contentMd5, BlobRequestConditions requestConditions)
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
BlobHttpHeaders
headers = newBlobHttpHeaders
() .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
accessConditions = newBlobRequestConditions
() .setLeaseId(leaseId) .setIfUnmodifiedSince(OffsetDateTime
.now().minusDays(3)); client.uploadWithResponse(data, length, headers, metadata,AccessTier
.HOT, md5, accessConditions) .subscribe(response ->System
.out.printf("Uploaded BlockBlob MD5 is %s%n",Base64
.getEncoder().encodeToString(response.getValue().getContentMd5())));
data
- The data to write to the blob. Note that this 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.length
- The exact length of the data. It is important that this value match precisely the length of the
data emitted by the Flux
.headers
- BlobHttpHeaders
metadata
- Metadata to associate with the blob.tier
- AccessTier
for the destination blob.contentMd5
- An MD5 hash of the blob content. This hash is used to verify the integrity of the blob during
transport. When this header is specified, the storage service compares the hash of the content that has arrived
with this header value. Note that this MD5 hash is not stored with the blob. If the two hashes do not match, the
operation will fail.requestConditions
- BlobRequestConditions
public Mono<Void> stageBlock(String base64BlockId, Flux<ByteBuffer> data, long length)
Note that the data passed must be replayable if retries are enabled (the default). In other words, the
base64BlockId
- A Base64 encoded String
that specifies the ID for this block. Note that all block
ids for a given blob must be the same length.data
- The data to write to the block. Note that this 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.length
- The exact length of the data. It is important that this value match precisely the length of the
data emitted by the Flux
.Code Samples
client.stageBlock(base64BlockID, data, length) .subscribe( response ->System
.out.println("Staging block completed"), error ->System
.out.printf("Error when calling stage Block: %s", error));
public Mono<Response<Void>> stageBlockWithResponse(String base64BlockId, Flux<ByteBuffer> data, long length, byte[] contentMd5, String leaseId)
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()));
base64BlockId
- A Base64 encoded String
that specifies the ID for this block. Note that all block
ids for a given blob must be the same length.data
- The data to write to the block. Note that this 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.length
- The exact length of the data. It is important that this value match precisely the length of the
data emitted by the Flux
.contentMd5
- An MD5 hash of the block content. This hash is used to verify the integrity of the block during
transport. When this header is specified, the storage service compares the hash of the content that has arrived
with this header value. Note that this MD5 hash is not stored with the blob. If the two hashes do not match, the
operation will fail.leaseId
- The lease ID the active lease on the blob must match.public Mono<Void> stageBlockFromUrl(String base64BlockId, String sourceUrl, BlobRange sourceRange)
Code Samples
client.stageBlockFromUrl(base64BlockID, sourceUrl, newBlobRange
(offset, count)) .subscribe( response ->System
.out.println("Staging block completed"), error ->System
.out.printf("Error when calling stage Block: %s", error));
base64BlockId
- A Base64 encoded String
that specifies the ID for this block. Note that all block
ids for a given blob must be the same length.sourceUrl
- The url to the blob that will be the source of the copy. A source blob in the same storage
account can be authenticated via Shared Key. However, if the source is a blob in another account, the source blob
must either be public or must be authenticated via a shared access signature. If the source blob is public, no
authentication is required to perform the operation.sourceRange
- BlobRange
public Mono<Response<Void>> stageBlockFromUrlWithResponse(String base64BlockId, String sourceUrl, BlobRange sourceRange, byte[] sourceContentMd5, String leaseId, BlobRequestConditions sourceRequestConditions)
Code Samples
BlobRequestConditions
sourceRequestConditions = newBlobRequestConditions
() .setIfUnmodifiedSince(OffsetDateTime
.now().minusDays(3)); client.stageBlockFromUrlWithResponse(base64BlockID, sourceUrl, newBlobRange
(offset, count), null, leaseId, sourceRequestConditions).subscribe(response ->System
.out.printf("Staging block from URL completed with status %d%n", response.getStatusCode()));
base64BlockId
- A Base64 encoded String
that specifies the ID for this block. Note that all block
ids for a given blob must be the same length.sourceUrl
- The url to the blob that will be the source of the copy. A source blob in the same storage
account can be authenticated via Shared Key. However, if the source is a blob in another account, the source blob
must either be public or must be authenticated via a shared access signature. If the source blob is public, no
authentication is required to perform the operation.sourceRange
- BlobRange
sourceContentMd5
- An MD5 hash of the block content. This hash is used to verify the integrity of the block
during transport. When this header is specified, the storage service compares the hash of the content that has
arrived with this header value. Note that this MD5 hash is not stored with the blob. If the two hashes do not
match, the operation will fail.leaseId
- The lease ID that the active lease on the blob must match.sourceRequestConditions
- BlobRequestConditions
public Mono<BlockList> listBlocks(BlockListType listType)
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.getSize()));System
.out.println("Uncommitted Blocks:"); block.getUncommittedBlocks().forEach(b ->System
.out.printf("Name: %s, Size: %d", b.getName(), b.getSize())); });
listType
- Specifies which type of blocks to return.public Mono<Response<BlockList>> listBlocksWithResponse(BlockListType listType, String leaseId)
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.getSize()));System
.out.println("Uncommitted Blocks:"); block.getUncommittedBlocks().forEach(b ->System
.out.printf("Name: %s, Size: %d", b.getName(), b.getSize())); });
listType
- Specifies which type of blocks to return.leaseId
- The lease ID the active lease on the blob must match.public Mono<BlockBlobItem> commitBlockList(List<String> base64BlockIds)
Code Samples
client.commitBlockList(Collections
.singletonList(base64BlockID)).subscribe(response ->System
.out.printf("Committing block list completed. Last modified: %s%n", response.getLastModified()));
base64BlockIds
- A list of base64 encode String
s that specifies the block IDs to be committed.public Mono<Response<BlockBlobItem>> commitBlockListWithResponse(List<String> base64BlockIds, BlobHttpHeaders headers, Map<String,String> metadata, AccessTier tier, BlobRequestConditions requestConditions)
Code Samples
BlobHttpHeaders
headers = newBlobHttpHeaders
() .setContentMd5("data".getBytes(StandardCharsets
.UTF_8)) .setContentLanguage("en-US") .setContentType("binary");Map
<String
,String
> metadata =Collections
.singletonMap("metadata", "value");BlobRequestConditions
accessConditions = newBlobRequestConditions
() .setLeaseId(leaseId) .setIfUnmodifiedSince(OffsetDateTime
.now().minusDays(3)); client.commitBlockListWithResponse(Collections
.singletonList(base64BlockID), headers, metadata,AccessTier
.HOT, accessConditions).subscribe(response ->System
.out.printf("Committing block list completed with status %d%n", response.getStatusCode()));
base64BlockIds
- A list of base64 encode String
s that specifies the block IDs to be committed.headers
- BlobHttpHeaders
metadata
- Metadata to associate with the blob.tier
- AccessTier
for the destination blob.requestConditions
- BlobRequestConditions
Copyright © 2019 Microsoft Corporation. All rights reserved.