Sdílet prostřednictvím


AppendBlobAsyncClient Class

public final class AppendBlobAsyncClient
extends BlobAsyncClientBase

Client to an append blob. It may only be instantiated through a buildAppendBlobAsyncClient() or via the method getAppendBlobAsyncClient(). 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.

This client contains operations on a blob. Operations on a container are available on BlobContainerAsyncClient, and operations on the service are available on BlobServiceAsyncClient.

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_APPEND_BLOCK_BYTES

Deprecated

Indicates the maximum number of bytes that can be sent in a call to appendBlock.

static final int MAX_BLOCKS

Deprecated

Indicates the maximum number of blocks allowed in an append blob.

Method Summary

Modifier and Type Method and Description
Mono<AppendBlobItem> appendBlock(Flux<ByteBuffer> data, long length)

Commits a new block of data to the end of the existing append blob.

Mono<AppendBlobItem> appendBlockFromUrl(String sourceUrl, BlobRange sourceRange)

Commits a new block of data from another blob to the end of this append blob.

Mono<Response<AppendBlobItem>> appendBlockFromUrlWithResponse(AppendBlobAppendBlockFromUrlOptions options)

Commits a new block of data from another blob to the end of this append blob.

Mono<Response<AppendBlobItem>> appendBlockFromUrlWithResponse(String sourceUrl, BlobRange sourceRange, byte[] sourceContentMD5, AppendBlobRequestConditions destRequestConditions, BlobRequestConditions sourceRequestConditions)

Commits a new block of data from another blob to the end of this append blob.

Mono<Response<AppendBlobItem>> appendBlockWithResponse(Flux<ByteBuffer> data, long length, byte[] contentMd5, AppendBlobRequestConditions appendBlobRequestConditions)

Commits a new block of data to the end of the existing append blob.

Mono<AppendBlobItem> create()

Creates a 0-length append blob.

Mono<AppendBlobItem> create(boolean overwrite)

Creates a 0-length append blob.

Mono<AppendBlobItem> createIfNotExists()

Creates a 0-length append blob if it does not exist.

Mono<Response<AppendBlobItem>> createIfNotExistsWithResponse(AppendBlobCreateOptions options)

Creates a 0-length append blob if it does not exist.

Mono<Response<AppendBlobItem>> createWithResponse(BlobHttpHeaders headers, Map<String,String> metadata, BlobRequestConditions requestConditions)

Creates a 0-length append blob.

Mono<Response<AppendBlobItem>> createWithResponse(AppendBlobCreateOptions options)

Creates a 0-length append blob.

AppendBlobAsyncClient getCustomerProvidedKeyAsyncClient(CustomerProvidedKey customerProvidedKey)

Creates a new AppendBlobAsyncClient with the specified customerProvidedKey.

AppendBlobAsyncClient getEncryptionScopeAsyncClient(String encryptionScope)

Creates a new AppendBlobAsyncClient with the specified encryptionScope.

int getMaxAppendBlockBytes()

Get the max number of append block bytes based on service version being used.

int getMaxBlocks()

Get the maximum number of blocks allowed in an append blob.

Mono<Void> seal()

Seals an append blob, making it read only.

Mono<Response<Void>> sealWithResponse(AppendBlobSealOptions options)

Seals an append blob, making it read only.

Methods inherited from BlobAsyncClientBase

Methods inherited from java.lang.Object

Field Details

MAX_APPEND_BLOCK_BYTES

@Deprecated
public static final int MAX_APPEND_BLOCK_BYTES

Deprecated

Indicates the maximum number of bytes that can be sent in a call to appendBlock.

MAX_BLOCKS

@Deprecated
public static final int MAX_BLOCKS

Deprecated

Indicates the maximum number of blocks allowed in an append blob.

Method Details

appendBlock

public Mono appendBlock(Flux data, long length)

Commits a new block of data to the end of the existing append blob.

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. For service versions 2022-11-02 and later, the max block size is 100 MB. For previous versions, the max block size is 4 MB. For more information, see the Azure Docs.

Code Samples

client.appendBlock(data, length).subscribe(response ->
     System.out.printf("AppendBlob has %d committed blocks%n", response.getBlobCommittedBlockCount()));

Parameters:

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.

Returns:

Mono containing the information of the append blob operation.

appendBlockFromUrl

public Mono appendBlockFromUrl(String sourceUrl, BlobRange sourceRange)

Commits a new block of data from another blob to the end of this append blob.

Code Samples

client.appendBlockFromUrl(sourceUrl, new BlobRange(offset, count)).subscribe(response ->
     System.out.printf("AppendBlob has %d committed blocks%n", response.getBlobCommittedBlockCount()));

Parameters:

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 - The source BlobRange to copy.

Returns:

Mono containing the information of the append blob operation.

appendBlockFromUrlWithResponse

public Mono> appendBlockFromUrlWithResponse(AppendBlobAppendBlockFromUrlOptions options)

Commits a new block of data from another blob to the end of this append blob.

Code Samples

AppendBlobRequestConditions appendBlobRequestConditions = new AppendBlobRequestConditions()
     .setAppendPosition(POSITION)
     .setMaxSize(maxSize);

 BlobRequestConditions modifiedRequestConditions = new BlobRequestConditions()
     .setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));

 client.appendBlockFromUrlWithResponse(new AppendBlobAppendBlockFromUrlOptions(sourceUrl)
     .setSourceRange(new BlobRange(offset, count))
     .setDestinationRequestConditions(appendBlobRequestConditions)
     .setSourceRequestConditions(modifiedRequestConditions)).subscribe(response ->
     System.out.printf("AppendBlob has %d committed blocks%n", response.getValue().getBlobCommittedBlockCount()));

Parameters:

options - Parameters for the operation.

Returns:

A Mono containing Response<T> whose value contains the append blob operation.

appendBlockFromUrlWithResponse

public Mono> appendBlockFromUrlWithResponse(String sourceUrl, BlobRange sourceRange, byte[] sourceContentMD5, AppendBlobRequestConditions destRequestConditions, BlobRequestConditions sourceRequestConditions)

Commits a new block of data from another blob to the end of this append blob.

Code Samples

AppendBlobRequestConditions appendBlobRequestConditions = new AppendBlobRequestConditions()
     .setAppendPosition(POSITION)
     .setMaxSize(maxSize);

 BlobRequestConditions modifiedRequestConditions = new BlobRequestConditions()
     .setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));

 client.appendBlockFromUrlWithResponse(sourceUrl, new BlobRange(offset, count), null,
     appendBlobRequestConditions, modifiedRequestConditions).subscribe(response ->
     System.out.printf("AppendBlob has %d committed blocks%n", response.getValue().getBlobCommittedBlockCount()));

Parameters:

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 from the source blob. If specified, the service will calculate the MD5 of the received data and fail the request if it does not match the provided MD5.
destRequestConditions - AppendBlobRequestConditions
sourceRequestConditions - BlobRequestConditions

Returns:

A Mono containing Response<T> whose value contains the append blob operation.

appendBlockWithResponse

public Mono> appendBlockWithResponse(Flux data, long length, byte[] contentMd5, AppendBlobRequestConditions appendBlobRequestConditions)

Commits a new block of data to the end of the existing append blob.

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. For service versions 2022-11-02 and later, the max block size is 100 MB. For previous versions, the max block size is 4 MB. For more information, see the Azure Docs.

Code Samples

byte[] md5 = MessageDigest.getInstance("MD5").digest("data".getBytes(StandardCharsets.UTF_8));
 AppendBlobRequestConditions requestConditions = new AppendBlobRequestConditions()
     .setAppendPosition(POSITION)
     .setMaxSize(maxSize);

 client.appendBlockWithResponse(data, length, md5, requestConditions).subscribe(response ->
     System.out.printf("AppendBlob has %d committed blocks%n", response.getValue().getBlobCommittedBlockCount()));

Parameters:

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.
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.
appendBlobRequestConditions - AppendBlobRequestConditions

Returns:

A Mono containing Response<T> whose value contains the append blob operation.

create

public Mono create()

Creates a 0-length append blob. Call appendBlock to append data to an append blob. By default this method will not overwrite an existing blob.

Code Samples

client.create().subscribe(response ->
     System.out.printf("Created AppendBlob at %s%n", response.getLastModified()));

Returns:

A Mono containing the information of the created appended blob.

create

public Mono create(boolean overwrite)

Creates a 0-length append blob. Call appendBlock to append data to an append blob.

Code Samples

boolean overwrite = false; // Default behavior
 client.create(overwrite).subscribe(response ->
     System.out.printf("Created AppendBlob at %s%n", response.getLastModified()));

Parameters:

overwrite - Whether to overwrite, should data exist on the blob.

Returns:

A Mono containing the information of the created appended blob.

createIfNotExists

public Mono createIfNotExists()

Creates a 0-length append blob if it does not exist. Call appendBlock to append data to an append blob.

Code Samples

client.createIfNotExists().subscribe(response ->
     System.out.printf("Created AppendBlob at %s%n", response.getLastModified()));

Returns:

A reactive response Mono signaling completion. AppendBlobItem contains the information of the created appended blob.

createIfNotExistsWithResponse

public Mono> createIfNotExistsWithResponse(AppendBlobCreateOptions options)

Creates a 0-length append blob if it does not exist. Call appendBlock to append data to an append blob.

Code Samples

BlobHttpHeaders headers = new BlobHttpHeaders()
     .setContentType("binary")
     .setContentLanguage("en-US");
 Map<String, String> metadata = Collections.singletonMap("metadata", "value");
 Map<String, String> tags = Collections.singletonMap("tag", "value");

 client.createIfNotExistsWithResponse(new AppendBlobCreateOptions().setHeaders(headers)
     .setMetadata(metadata).setTags(tags)).subscribe(response -> {
         if (response.getStatusCode() == 409) {
             System.out.println("Already exists.");
         } else {
             System.out.println("successfully created.");
         }
     });

Parameters:

Returns:

A Mono containing Response<T> signaling completion, whose value contains a AppendBlobItem containing information about the append blob. If Response<T>'s status code is 201, a new page blob was successfully created. If status code is 409, an append blob already existed at this location.

createWithResponse

public Mono> createWithResponse(BlobHttpHeaders headers, Map metadata, BlobRequestConditions requestConditions)

Creates a 0-length append blob. Call appendBlock to append data to an append blob.

To avoid overwriting, pass "*" to setIfNoneMatch(String ifNoneMatch).

Code Samples

BlobHttpHeaders headers = new BlobHttpHeaders()
     .setContentType("binary")
     .setContentLanguage("en-US");
 Map<String, String> metadata = Collections.singletonMap("metadata", "value");
 BlobRequestConditions requestConditions = new BlobRequestConditions().setLeaseId(leaseId)
     .setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));

 client.createWithResponse(headers, metadata, requestConditions).subscribe(response ->
     System.out.printf("Created AppendBlob at %s%n", response.getValue().getLastModified()));

Parameters:

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.
requestConditions - BlobRequestConditions

Returns:

A Mono containing Response<T> whose value contains the created appended blob.

createWithResponse

public Mono> createWithResponse(AppendBlobCreateOptions options)

Creates a 0-length append blob. Call appendBlock to append data to an append blob.

To avoid overwriting, pass "*" to setIfNoneMatch(String ifNoneMatch).

Code Samples

BlobHttpHeaders headers = new BlobHttpHeaders()
     .setContentType("binary")
     .setContentLanguage("en-US");
 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.createWithResponse(new AppendBlobCreateOptions().setHeaders(headers).setMetadata(metadata)
     .setTags(tags).setRequestConditions(requestConditions)).subscribe(response ->
     System.out.printf("Created AppendBlob at %s%n", response.getValue().getLastModified()));

Parameters:

Returns:

A Mono containing Response<T> whose value contains the created appended blob.

getCustomerProvidedKeyAsyncClient

public AppendBlobAsyncClient getCustomerProvidedKeyAsyncClient(CustomerProvidedKey customerProvidedKey)

Creates a new AppendBlobAsyncClient with the specified customerProvidedKey.

Overrides:

AppendBlobAsyncClient.getCustomerProvidedKeyAsyncClient(CustomerProvidedKey customerProvidedKey)

Parameters:

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

Returns:

a AppendBlobAsyncClient with the specified customerProvidedKey.

getEncryptionScopeAsyncClient

public AppendBlobAsyncClient getEncryptionScopeAsyncClient(String encryptionScope)

Creates a new AppendBlobAsyncClient with the specified encryptionScope.

Overrides:

AppendBlobAsyncClient.getEncryptionScopeAsyncClient(String encryptionScope)

Parameters:

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

Returns:

a AppendBlobAsyncClient with the specified encryptionScope.

getMaxAppendBlockBytes

public int getMaxAppendBlockBytes()

Get the max number of append block bytes based on service version being used. Service versions 2022-11-02 and above support uploading block bytes up to 100MB, all older service versions support up to 4MB.

Returns:

the max number of block bytes that can be uploaded based on service version.

getMaxBlocks

public int getMaxBlocks()

Get the maximum number of blocks allowed in an append blob.

Returns:

the max number of blocks that can be uploaded in an append blob.

seal

public Mono seal()

Seals an append blob, making it read only. Any subsequent appends will fail.

Code Samples

client.seal().subscribe(response -> System.out.println("Sealed AppendBlob"));

Returns:

A reactive response signalling completion.

sealWithResponse

public Mono> sealWithResponse(AppendBlobSealOptions options)

Seals an append blob, making it read only. Any subsequent appends will fail.

Code Samples

AppendBlobRequestConditions requestConditions = new AppendBlobRequestConditions().setLeaseId(leaseId)
     .setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));

 client.sealWithResponse(new AppendBlobSealOptions().setRequestConditions(requestConditions))
     .subscribe(response -> System.out.println("Sealed AppendBlob"));

Parameters:

Returns:

A reactive response signalling completion.

Applies to