public class BlobAsyncClient extends BlobAsyncClientBase
This client is instantiated through BlobClientBuilder
or retrieved via
getBlobAsyncClient
.
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.
Please refer to the Azure Docs for more information.
Modifier and Type | Field and Description |
---|---|
static int |
BLOB_DEFAULT_UPLOAD_BLOCK_SIZE |
accountName, azureBlobStorage
Modifier | Constructor and Description |
---|---|
protected |
BlobAsyncClient(com.azure.storage.blob.implementation.AzureBlobStorageImpl azureBlobStorage,
String snapshot,
CpkInfo cpk,
String accountName)
Constructor for use by
BlobClientBuilder . |
Modifier and Type | Method and Description |
---|---|
AppendBlobAsyncClient |
getAppendBlobAsyncClient()
Creates a new
AppendBlobAsyncClient associated to this blob. |
BlockBlobAsyncClient |
getBlockBlobAsyncClient()
Creates a new
BlockBlobAsyncClient associated to this blob. |
PageBlobAsyncClient |
getPageBlobAsyncClient()
Creates a new
PageBlobAsyncClient associated to this blob. |
BlobAsyncClient |
getSnapshotClient(String snapshot)
Creates a new
BlobAsyncClient linked to the snapshot of this blob resource. |
Mono<BlockBlobItem> |
upload(Flux<ByteBuffer> data,
ParallelTransferOptions parallelTransferOptions)
Creates a new block blob, or updates the content of an existing block blob.
|
protected AsynchronousFileChannel |
uploadFileResourceSupplier(String filePath)
Resource Supplier for UploadFile
|
Mono<Void> |
uploadFromFile(String filePath)
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,
BlobAccessConditions accessConditions)
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(Flux<ByteBuffer> data,
ParallelTransferOptions parallelTransferOptions,
BlobHTTPHeaders headers,
Map<String,String> metadata,
AccessTier tier,
BlobAccessConditions accessConditions)
Creates a new block blob, or updates the content of an existing block blob.
|
abortCopyFromURL, abortCopyFromURLWithResponse, copyFromURL, copyFromURLWithResponse, createSnapshot, createSnapshotWithResponse, delete, deleteWithResponse, download, downloadToFile, downloadToFileWithResponse, downloadWithResponse, exists, existsWithResponse, getAccountInfo, getAccountInfoWithResponse, getAccountName, getBlobName, getBlobUrl, getContainerName, getCustomerProvidedKey, getHttpPipeline, getProperties, getPropertiesWithResponse, getSnapshotId, isSnapshot, setAccessTier, setAccessTierWithResponse, setHTTPHeaders, setHTTPHeadersWithResponse, setMetadata, setMetadataWithResponse, startCopyFromURL, startCopyFromURLWithResponse, undelete, undeleteWithResponse
public static final int BLOB_DEFAULT_UPLOAD_BLOCK_SIZE
protected BlobAsyncClient(com.azure.storage.blob.implementation.AzureBlobStorageImpl azureBlobStorage, String snapshot, CpkInfo cpk, String accountName)
BlobClientBuilder
.azureBlobStorage
- the API client for blob storagesnapshot
- The optional snapshot id of the snapshot blobcpk
- The optional client provided keyaccountName
- The account namepublic BlobAsyncClient getSnapshotClient(String snapshot)
BlobAsyncClient
linked to the snapshot
of this blob resource.getSnapshotClient
in class BlobAsyncClientBase
snapshot
- the identifier for a specific snapshot of this blobBlobAsyncClient
used to interact with the specific snapshot.public AppendBlobAsyncClient getAppendBlobAsyncClient()
AppendBlobAsyncClient
associated to this blob.AppendBlobAsyncClient
associated to this blob.public BlockBlobAsyncClient getBlockBlobAsyncClient()
BlockBlobAsyncClient
associated to this blob.BlockBlobAsyncClient
associated to this blob.public PageBlobAsyncClient getPageBlobAsyncClient()
PageBlobAsyncClient
associated to this blob.PageBlobAsyncClient
associated to this blob.public Mono<BlockBlobItem> upload(Flux<ByteBuffer> data, ParallelTransferOptions parallelTransferOptions)
Updating an existing block blob overwrites any existing metadata on the blob. 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)
. 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 = newParallelTransferOptions
() .setBlockSize(blockSize) .setNumBuffers(numBuffers); client.upload(data, parallelTransferOptions).subscribe(response ->System
.out.printf("Uploaded BlockBlob MD5 is %s%n",Base64
.getEncoder().encodeToString(response.getContentMD5())));
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.public Mono<Response<BlockBlobItem>> uploadWithResponse(Flux<ByteBuffer> data, ParallelTransferOptions parallelTransferOptions, BlobHTTPHeaders headers, Map<String,String> metadata, AccessTier tier, BlobAccessConditions accessConditions)
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 = newBlobHTTPHeaders
() .setBlobContentMD5("data".getBytes(StandardCharsets
.UTF_8)) .setBlobContentLanguage("en-US") .setBlobContentType("binary");Map
<String
,String
> metadata =Collections
.singletonMap("metadata", "value");BlobAccessConditions
accessConditions = newBlobAccessConditions
() .setLeaseAccessConditions(newLeaseAccessConditions
().setLeaseId(leaseId)) .setModifiedAccessConditions(newModifiedAccessConditions
() .setIfUnmodifiedSince(OffsetDateTime
.now().minusDays(3)));ParallelTransferOptions
parallelTransferOptions = newParallelTransferOptions
() .setBlockSize(blockSize) .setNumBuffers(numBuffers); client.uploadWithResponse(data, parallelTransferOptions, headers, metadata,AccessTier
.HOT, accessConditions) .subscribe(response ->System
.out.printf("Uploaded BlockBlob MD5 is %s%n",Base64
.getEncoder().encodeToString(response.getValue().getContentMD5())));
Using Progress Reporting
BlobHTTPHeaders
headers = newBlobHTTPHeaders
() .setBlobContentMD5("data".getBytes(StandardCharsets
.UTF_8)) .setBlobContentLanguage("en-US") .setBlobContentType("binary");Map
<String
,String
> metadata =Collections
.singletonMap("metadata", "value");BlobAccessConditions
accessConditions = newBlobAccessConditions
() .setLeaseAccessConditions(newLeaseAccessConditions
().setLeaseId(leaseId)) .setModifiedAccessConditions(newModifiedAccessConditions
() .setIfUnmodifiedSince(OffsetDateTime
.now().minusDays(3)));ParallelTransferOptions
parallelTransferOptions = newParallelTransferOptions
() .setBlockSize(blockSize) .setNumBuffers(numBuffers) .setProgressReceiver(bytesTransferred ->System
.out.printf( "Upload progress: %s bytes sent", bytesTransferred)); client.uploadWithResponse(data, parallelTransferOptions, headers, metadata,AccessTier
.HOT, 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. 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.tier
- AccessTier
for the destination blob.accessConditions
- BlobAccessConditions
public Mono<Void> uploadFromFile(String filePath)
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"));
filePath
- Path to the upload filepublic Mono<Void> uploadFromFile(String filePath, ParallelTransferOptions parallelTransferOptions, BlobHTTPHeaders headers, Map<String,String> metadata, AccessTier tier, BlobAccessConditions accessConditions)
Code Samples
BlobHTTPHeaders
headers = newBlobHTTPHeaders
() .setBlobContentMD5("data".getBytes(StandardCharsets
.UTF_8)) .setBlobContentLanguage("en-US") .setBlobContentType("binary");Map
<String
,String
> metadata =Collections
.singletonMap("metadata", "value");BlobAccessConditions
accessConditions = newBlobAccessConditions
() .setLeaseAccessConditions(newLeaseAccessConditions
().setLeaseId(leaseId)) .setModifiedAccessConditions(newModifiedAccessConditions
() .setIfUnmodifiedSince(OffsetDateTime
.now().minusDays(3))); client.uploadFromFile(filePath, newParallelTransferOptions
().setBlockSize(BlobAsyncClient
.BLOB_MAX_UPLOAD_BLOCK_SIZE), headers, metadata,AccessTier
.HOT, accessConditions) .doOnError(throwable ->System
.err.printf("Failed to upload from file %s%n", throwable.getMessage())) .subscribe(completion ->System
.out.println("Upload from file succeeded"));
filePath
- Path to the upload fileparallelTransferOptions
- ParallelTransferOptions
to use to upload from file. Number of parallel
transfers parameter is ignored.headers
- BlobHTTPHeaders
metadata
- Metadata to associate with the blob.tier
- AccessTier
for the destination blob.accessConditions
- BlobAccessConditions
IllegalArgumentException
- If blockSize
is less than 0 or greater than 100MBUncheckedIOException
- If an I/O error occursprotected AsynchronousFileChannel uploadFileResourceSupplier(String filePath)
filePath
- The path for the fileAsynchronousFileChannel
IOException
- an input output exception.Copyright © 2019 Microsoft Corporation. All rights reserved.