This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Download Microsoft Edge
More info about Internet Explorer and Microsoft Edge
This class provides a client that contains generic blob operations for Azure Storage Blobs. Operations allowed by the client are uploading and downloading, copying a blob, retrieving and setting metadata, retrieving and setting HTTP headers, and deleting and un-deleting a blob.
This client is instantiated through
BlobClientBuilder
or retrieved via
getBlobAsyncClient(String blobName)
.
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.
BlobAsyncClient(HttpPipeline pipeline, String url, BlobServiceVersion serviceVersion, String accountName, String containerName, String blobName, String snapshot, CpkInfo customerProvidedKey)
Protected constructor for use by
BlobClientBuilder
.
BlobAsyncClient(HttpPipeline pipeline, String url, BlobServiceVersion serviceVersion, String accountName, String containerName, String blobName, String snapshot, CpkInfo customerProvidedKey, EncryptionScope encryptionScope)
Protected constructor for use by
BlobClientBuilder
.
BlobAsyncClient(HttpPipeline pipeline, String url, BlobServiceVersion serviceVersion, String accountName, String containerName, String blobName, String snapshot, CpkInfo customerProvidedKey, EncryptionScope encryptionScope, String versionId)
Protected constructor for use by
BlobClientBuilder
.
upload(Flux<ByteBuffer> data, ParallelTransferOptions parallelTransferOptions, boolean overwrite)
Creates a new block blob, or updates the content of an existing block blob.
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.
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.
BLOB_DEFAULT_HTBB_UPLOAD_BLOCK_SIZE
public static final int BLOB_DEFAULT_HTBB_UPLOAD_BLOCK_SIZE
If a blob is known to be greater than 100MB, using a larger block size will trigger some server-side optimizations. If the block size is not set and the size of the blob is known to be greater than 100MB, this value will be used.
protected BlobAsyncClient(HttpPipeline pipeline, String url, BlobServiceVersion serviceVersion, String accountName, String containerName, String blobName, String snapshot, CpkInfo customerProvidedKey)
Protected constructor for use by
BlobClientBuilder
.
Parameters:
pipeline
- The pipeline used to send and receive service requests.
- The endpoint where to send service requests.
serviceVersion
- The version of the service to receive requests.
accountName
- The storage account name.
containerName
- The container name.
blobName
- The blob name.
snapshot
- The snapshot identifier for the blob, pass
null
to interact with the blob directly.
customerProvidedKey
- Customer provided key used during encryption of the blob's data on the server, pass
null
to allow the service to use its own encryption.
protected BlobAsyncClient(HttpPipeline pipeline, String url, BlobServiceVersion serviceVersion, String accountName, String containerName, String blobName, String snapshot, CpkInfo customerProvidedKey, EncryptionScope encryptionScope)
Protected constructor for use by
BlobClientBuilder
.
Parameters:
pipeline
- The pipeline used to send and receive service requests.
- The endpoint where to send service requests.
serviceVersion
- The version of the service to receive requests.
accountName
- The storage account name.
containerName
- The container name.
blobName
- The blob name.
snapshot
- The snapshot identifier for the blob, pass
null
to interact with the blob directly.
customerProvidedKey
- Customer provided key used during encryption of the blob's data on the server, pass
null
to allow the service to use its own encryption.
encryptionScope
- Encryption scope used during encryption of the blob's data on the server, pass
null
to allow the service to use its own encryption.
protected BlobAsyncClient(HttpPipeline pipeline, String url, BlobServiceVersion serviceVersion, String accountName, String containerName, String blobName, String snapshot, CpkInfo customerProvidedKey, EncryptionScope encryptionScope, String versionId)
Protected constructor for use by
BlobClientBuilder
.
Parameters:
pipeline
- The pipeline used to send and receive service requests.
- The endpoint where to send service requests.
serviceVersion
- The version of the service to receive requests.
accountName
- The storage account name.
containerName
- The container name.
blobName
- The blob name.
snapshot
- The snapshot identifier for the blob, pass
null
to interact with the blob directly.
customerProvidedKey
- Customer provided key used during encryption of the blob's data on the server, pass
null
to allow the service to use its own encryption.
encryptionScope
- Encryption scope used during encryption of the blob's data on the server, pass
null
to allow the service to use its own encryption.
versionId
- The version identifier for the blob, pass
null
to interact with the latest blob version.
getCustomerProvidedKeyAsyncClient
public BlobAsyncClient getCustomerProvidedKeyAsyncClient(CustomerProvidedKey customerProvidedKey)
Creates a new
BlobAsyncClient
with the specified
customerProvidedKey
.
Overrides:
BlobAsyncClient.getCustomerProvidedKeyAsyncClient(CustomerProvidedKey customerProvidedKey)
Parameters:
customerProvidedKey
- the
CustomerProvidedKey
for the blob,
pass
null
to use no customer provided key.
Returns:
getEncryptionScopeAsyncClient
public BlobAsyncClient getEncryptionScopeAsyncClient(String encryptionScope)
Creates a new
BlobAsyncClient
with the specified
encryptionScope
.
Overrides:
BlobAsyncClient.getEncryptionScopeAsyncClient(String encryptionScope)
Parameters:
encryptionScope
- the encryption scope for the blob, pass
null
to use no encryption scope.
Returns:
versionId
- the identifier for a specific version of this blob,
pass
null
to interact with the latest blob version.
Returns:
Creates a new block blob. By default, this method will not overwrite an existing blob.
Code Samples
client.upload(BinaryData.fromString("Data!")).subscribe(response ->
System.out.printf("Uploaded BlockBlob MD5 is %s%n",
Base64.getEncoder().encodeToString(response.getContentMd5())));
Creates a new block blob, or updates the content of an existing block blob.
Code Samples
boolean overwrite = false; // Default behavior
client.upload(BinaryData.fromString("Data!"), overwrite).subscribe(response ->
System.out.printf("Uploaded BlockBlob MD5 is %s%n",
Base64.getEncoder().encodeToString(response.getContentMd5())));
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 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(String base64BlockId, Flux<ByteBuffer> data, long length) and commitBlockList(List<String> base64BlockIds). 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 does 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())));
- 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 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(String base64BlockId, Flux<ByteBuffer> data, long length) and commitBlockList(List<String> base64BlockIds). 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 does 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())));
- 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, should the blob already exist.
Returns:
A reactive response containing the information of the uploaded block blob.
uploadFileResourceSupplier
@Deprecated
protected AsynchronousFileChannel uploadFileResourceSupplier(String filePath)
Deprecated
due to refactoring code to be in the common storage library.
RESERVED FOR INTERNAL USE. Resource Supplier for UploadFile.
Parameters:
filePath
- The path for the file
Returns:
AsynchronousFileChannel
Creates a new block blob with the content of the specified file. By default, this method will not overwrite an existing blob.
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"));
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"));
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.
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.uploadFromFile(filePath,
new ParallelTransferOptions().setBlockSizeLong(BlockBlobClient.MAX_STAGE_BLOCK_BYTES_LONG),
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"));
parallelTransferOptions
- ParallelTransferOptions to use to upload from file. Number of parallel
transfers parameter is ignored.
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.
- 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.
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.uploadFromFileWithResponse(new BlobUploadFromFileOptions(filePath)
.setParallelTransferOptions(
new ParallelTransferOptions().setBlockSizeLong(BlobAsyncClient.BLOB_MAX_UPLOAD_BLOCK_SIZE))
.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"));
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 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(String base64BlockId, Flux<ByteBuffer> data, long length) and commitBlockList(List<String> base64BlockIds). 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 does 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.
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));
ParallelTransferOptions parallelTransferOptions = new ParallelTransferOptions().setBlockSizeLong(blockSize)
.setMaxConcurrency(maxConcurrency).setProgressListener(bytesTransferred ->
System.out.printf("Upload progress: %s bytes sent", bytesTransferred));
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())));
Using Progress Reporting
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));
ParallelTransferOptions parallelTransferOptions = new ParallelTransferOptions().setBlockSizeLong(blockSize)
.setMaxConcurrency(maxConcurrency).setProgressListener(bytesTransferred ->
System.out.printf("Upload progress: %s bytes sent", bytesTransferred));
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())));
options
- BlobParallelUploadOptions. 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.
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 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(String base64BlockId, Flux<ByteBuffer> data, long length) and commitBlockList(List<String> base64BlockIds). 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 does 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.
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));
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())));
Using Progress Reporting
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));
ParallelTransferOptions parallelTransferOptions = new ParallelTransferOptions()
.setBlockSizeLong(blockSize)
.setMaxConcurrency(maxConcurrency)
.setProgressListener(bytesTransferred -> System.out.printf("Upload progress: %s bytes sent", bytesTransferred));
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())));
- 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.
- AccessTier for the destination blob.
requestConditions
- BlobRequestConditions
Returns:
A reactive response containing the information of the uploaded block blob.