public class BlobAsyncClientBase extends Object
This client offers the ability to download blobs. Note that uploading data is specific to each type of blob. Please
refer to the BlockBlobClient
, PageBlobClient
, or AppendBlobClient
for upload options.
Modifier and Type | Field and Description |
---|---|
protected String |
accountName |
protected com.azure.storage.blob.implementation.AzureBlobStorageImpl |
azureBlobStorage |
protected String |
blobName |
protected String |
containerName |
protected BlobServiceVersion |
serviceVersion |
Modifier | Constructor and Description |
---|---|
protected |
BlobAsyncClientBase(HttpPipeline pipeline,
String url,
BlobServiceVersion serviceVersion,
String accountName,
String containerName,
String blobName,
String snapshot,
CpkInfo customerProvidedKey)
Package-private constructor for use by
SpecializedBlobClientBuilder . |
Modifier and Type | Method and Description |
---|---|
Mono<Void> |
abortCopyFromUrl(String copyId)
Stops a pending copy that was previously started and leaves a destination blob with 0 length and metadata.
|
Mono<Response<Void>> |
abortCopyFromUrlWithResponse(String copyId,
String leaseId)
Stops a pending copy that was previously started and leaves a destination blob with 0 length and metadata.
|
PollerFlux<BlobCopyInfo,Void> |
beginCopy(String sourceUrl,
Duration pollInterval)
Copies the data at the source URL to a blob.
|
PollerFlux<BlobCopyInfo,Void> |
beginCopy(String sourceUrl,
Map<String,String> metadata,
AccessTier tier,
RehydratePriority priority,
RequestConditions sourceModifiedAccessConditions,
BlobRequestConditions destAccessConditions,
Duration pollInterval)
Copies the data at the source URL to a blob.
|
Mono<String> |
copyFromUrl(String copySource)
Copies the data at the source URL to a blob and waits for the copy to complete before returning a response.
|
Mono<Response<String>> |
copyFromUrlWithResponse(String copySource,
Map<String,String> metadata,
AccessTier tier,
RequestConditions sourceModifiedAccessConditions,
BlobRequestConditions destAccessConditions)
Copies the data at the source URL to a blob and waits for the copy to complete before returning a response.
|
Mono<BlobAsyncClientBase> |
createSnapshot()
Creates a read-only snapshot of the blob.
|
Mono<Response<BlobAsyncClientBase>> |
createSnapshotWithResponse(Map<String,String> metadata,
BlobRequestConditions accessConditions)
Creates a read-only snapshot of the blob.
|
Mono<Void> |
delete()
Deletes the specified blob or snapshot.
|
Mono<Response<Void>> |
deleteWithResponse(DeleteSnapshotsOptionType deleteBlobSnapshotOptions,
BlobRequestConditions accessConditions)
Deletes the specified blob or snapshot.
|
Flux<ByteBuffer> |
download()
Reads the entire blob.
|
Mono<BlobProperties> |
downloadToFile(String filePath)
Downloads the entire blob into a file specified by the path.
|
Mono<Response<BlobProperties>> |
downloadToFileWithResponse(String filePath,
BlobRange range,
ParallelTransferOptions parallelTransferOptions,
DownloadRetryOptions options,
BlobRequestConditions accessConditions,
boolean rangeGetContentMD5)
Downloads the entire blob into a file specified by the path.
|
Mono<BlobDownloadAsyncResponse> |
downloadWithResponse(BlobRange range,
DownloadRetryOptions options,
BlobRequestConditions accessConditions,
boolean rangeGetContentMD5)
Reads a range of bytes from a blob.
|
Mono<Boolean> |
exists()
Determines if the blob this client represents exists in the cloud.
|
Mono<Response<Boolean>> |
existsWithResponse()
Determines if the blob this client represents exists in the cloud.
|
Mono<StorageAccountInfo> |
getAccountInfo()
Returns the sku name and account kind for the account.
|
Mono<Response<StorageAccountInfo>> |
getAccountInfoWithResponse()
Returns the sku name and account kind for the account.
|
String |
getAccountName()
Get associated account name.
|
String |
getBlobName()
Decodes and gets the blob name.
|
String |
getBlobUrl()
Gets the URL of the blob represented by this client.
|
String |
getContainerName()
Get the container name.
|
CpkInfo |
getCustomerProvidedKey()
Gets the
CpkInfo used to encrypt this blob's content on the server. |
HttpPipeline |
getHttpPipeline()
Gets the
HttpPipeline powering this client. |
Mono<BlobProperties> |
getProperties()
Returns the blob's metadata and properties.
|
Mono<Response<BlobProperties>> |
getPropertiesWithResponse(BlobRequestConditions accessConditions)
Returns the blob's metadata and properties.
|
BlobServiceVersion |
getServiceVersion()
Gets the service version the client is using.
|
BlobAsyncClientBase |
getSnapshotClient(String snapshot)
Creates a new
BlobAsyncClientBase linked to the snapshot of this blob resource. |
String |
getSnapshotId()
Gets the snapshotId for a blob resource
|
boolean |
isSnapshot()
Determines if a blob is a snapshot
|
Mono<Void> |
setAccessTier(AccessTier tier)
Sets the tier on a blob.
|
Mono<Response<Void>> |
setAccessTierWithResponse(AccessTier tier,
RehydratePriority priority,
String leaseId)
Sets the tier on a blob.
|
Mono<Void> |
setHttpHeaders(BlobHttpHeaders headers)
Changes a blob's HTTP header properties.
|
Mono<Response<Void>> |
setHttpHeadersWithResponse(BlobHttpHeaders headers,
BlobRequestConditions accessConditions)
Changes a blob's HTTP header properties.
|
Mono<Void> |
setMetadata(Map<String,String> metadata)
Changes a blob's metadata.
|
Mono<Response<Void>> |
setMetadataWithResponse(Map<String,String> metadata,
BlobRequestConditions accessConditions)
Changes a blob's metadata.
|
Mono<Void> |
undelete()
Undelete restores the content and metadata of a soft-deleted blob and/or any associated soft-deleted snapshots.
|
Mono<Response<Void>> |
undeleteWithResponse()
Undelete restores the content and metadata of a soft-deleted blob and/or any associated soft-deleted snapshots.
|
protected final com.azure.storage.blob.implementation.AzureBlobStorageImpl azureBlobStorage
protected final String accountName
protected final String containerName
protected final String blobName
protected final BlobServiceVersion serviceVersion
protected BlobAsyncClientBase(HttpPipeline pipeline, String url, BlobServiceVersion serviceVersion, String accountName, String containerName, String blobName, String snapshot, CpkInfo customerProvidedKey)
SpecializedBlobClientBuilder
.pipeline
- The pipeline used to send and receive service requests.url
- 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.public BlobAsyncClientBase getSnapshotClient(String snapshot)
BlobAsyncClientBase
linked to the snapshot
of this blob resource.snapshot
- the identifier for a specific snapshot of this blobBlobAsyncClientBase
used to interact with the specific snapshot.public String getBlobUrl()
public final String getContainerName()
Code Samples
String
containerName = client.getContainerName();System
.out.println("The name of the container is " + containerName);
public final String getBlobName()
Code Samples
String
blobName = client.getBlobName();System
.out.println("The name of the blob is " + blobName);
public HttpPipeline getHttpPipeline()
HttpPipeline
powering this client.public CpkInfo getCustomerProvidedKey()
CpkInfo
used to encrypt this blob's content on the server.public String getAccountName()
public BlobServiceVersion getServiceVersion()
public String getSnapshotId()
public boolean isSnapshot()
public Mono<Boolean> exists()
Code Samples
client.exists().subscribe(response -> System
.out.printf("Exists? %b%n", response));
public Mono<Response<Boolean>> existsWithResponse()
Code Samples
client.existsWithResponse().subscribe(response -> System
.out.printf("Exists? %b%n", response.getValue()));
public PollerFlux<BlobCopyInfo,Void> beginCopy(String sourceUrl, Duration pollInterval)
Code Samples
client.beginCopy(url,Duration
.ofSeconds(3)) .subscribe(response ->System
.out.printf("Copy identifier: %s%n", response));
For more information, see the Azure Docs
sourceUrl
- The source URL to copy from. URLs outside of Azure may only be copied to block blobs.pollInterval
- Duration between each poll for the copy status. If none is specified, a default of one second
is used.PollerFlux
that polls the blob copy operation until it has completed, has failed, or has been
cancelled.public PollerFlux<BlobCopyInfo,Void> beginCopy(String sourceUrl, Map<String,String> metadata, AccessTier tier, RehydratePriority priority, RequestConditions sourceModifiedAccessConditions, BlobRequestConditions destAccessConditions, Duration pollInterval)
Starting a copy operation
Starting a copy operation and polling on the responses.Map
<String
,String
> metadata =Collections
.singletonMap("metadata", "value");RequestConditions
modifiedAccessConditions = newRequestConditions
() .setIfUnmodifiedSince(OffsetDateTime
.now().minusDays(7));BlobRequestConditions
blobAccessConditions = newBlobRequestConditions
().setLeaseId(leaseId); client.beginCopy(url, metadata,AccessTier
.HOT,RehydratePriority
.STANDARD, modifiedAccessConditions, blobAccessConditions,Duration
.ofSeconds(2)) .subscribe(response -> {BlobCopyInfo
info = response.getValue();System
.out.printf("CopyId: %s. Status: %s%n", info.getCopyId(), info.getCopyStatus()); });
Cancelling a copy operation
Map
<String
,String
> metadata =Collections
.singletonMap("metadata", "value");RequestConditions
modifiedAccessConditions = newRequestConditions
() .setIfUnmodifiedSince(OffsetDateTime
.now().minusDays(7));BlobRequestConditions
blobRequestConditions = newBlobRequestConditions
().setLeaseId(leaseId);PollerFlux
<BlobCopyInfo
,Void
> poller = client.beginCopy(url, metadata,AccessTier
.HOT,RehydratePriority
.STANDARD, modifiedAccessConditions, blobRequestConditions,Duration
.ofSeconds(2)); poller.take(Duration
.ofMinutes(30)) .last() .flatMap(asyncPollResponse -> { if (!asyncPollResponse.getStatus().isComplete()) { return asyncPollResponse .cancelOperation() .then(Mono
.error(newRuntimeException
("Blob copy taking long time, " + "operation is cancelled!"))); } returnMono
.just(asyncPollResponse); }).block();
For more information, see the Azure Docs
sourceUrl
- The source URL to copy from. URLs outside of Azure may only be copied to block blobs.metadata
- Metadata to associate with the destination blob.tier
- AccessTier
for the destination blob.priority
- RehydratePriority
for rehydrating the blob.sourceModifiedAccessConditions
- RequestConditions
against the source. Standard HTTP
Access conditions related to the modification of data. ETag and LastModifiedTime are used to construct
conditions related to when the blob was changed relative to the given request. The request will fail if the
specified condition is not satisfied.destAccessConditions
- BlobRequestConditions
against the destination.pollInterval
- Duration between each poll for the copy status. If none is specified, a default of one second
is used.PollerFlux
that polls the blob copy operation until it has completed, has failed, or has been
cancelled.public Mono<Void> abortCopyFromUrl(String copyId)
Code Samples
client.abortCopyFromUrl(copyId).doOnSuccess(response -> System
.out.println("Aborted copy from URL"));
For more information, see the Azure Docs
copyId
- The id of the copy operation to abort.BlobAsyncClientBase.copyFromUrl(String)
,
BlobAsyncClientBase.beginCopy(String, Duration)
,
BlobAsyncClientBase.beginCopy(String, Map, AccessTier, RehydratePriority, RequestConditions, BlobRequestConditions, Duration)
public Mono<Response<Void>> abortCopyFromUrlWithResponse(String copyId, String leaseId)
Code Samples
client.abortCopyFromUrlWithResponse(copyId, leaseId)
.subscribe(response -> System
.out.printf("Aborted copy completed with status %d%n", response.getStatusCode()));
For more information, see the Azure Docs
copyId
- The id of the copy operation to abort.leaseId
- The lease ID the active lease on the blob must match.BlobAsyncClientBase.copyFromUrl(String)
,
BlobAsyncClientBase.beginCopy(String, Duration)
,
BlobAsyncClientBase.beginCopy(String, Map, AccessTier, RehydratePriority, RequestConditions, BlobRequestConditions, Duration)
public Mono<String> copyFromUrl(String copySource)
Code Samples
client.copyFromUrl(url).subscribe(response -> System
.out.printf("Copy identifier: %s%n", response));
For more information, see the Azure Docs
copySource
- The source URL to copy from.public Mono<Response<String>> copyFromUrlWithResponse(String copySource, Map<String,String> metadata, AccessTier tier, RequestConditions sourceModifiedAccessConditions, BlobRequestConditions destAccessConditions)
Code Samples
Map
<String
,String
> metadata =Collections
.singletonMap("metadata", "value");RequestConditions
modifiedAccessConditions = newRequestConditions
() .setIfUnmodifiedSince(OffsetDateTime
.now().minusDays(7));BlobRequestConditions
blobRequestConditions = newBlobRequestConditions
().setLeaseId(leaseId); client.copyFromUrlWithResponse(url, metadata,AccessTier
.HOT, modifiedAccessConditions, blobRequestConditions) .subscribe(response ->System
.out.printf("Copy identifier: %s%n", response));
For more information, see the Azure Docs
copySource
- The source URL to copy from. URLs outside of Azure may only be copied to block blobs.metadata
- Metadata to associate with the destination blob.tier
- AccessTier
for the destination blob.sourceModifiedAccessConditions
- RequestConditions
against the source. Standard HTTP Access
conditions related to the modification of data. ETag and LastModifiedTime are used to construct conditions
related to when the blob was changed relative to the given request. The request will fail if the specified
condition is not satisfied.destAccessConditions
- BlobRequestConditions
against the destination.public Flux<ByteBuffer> download()
BlockBlobClient
, PageBlobClient
, or
AppendBlobClient
.
Code Samples
ByteArrayOutputStream
downloadData = newByteArrayOutputStream
(); client.download().subscribe(piece -> { try { downloadData.write(piece.array()); } catch (IOException
ex) { throw newUncheckedIOException
(ex); } });
For more information, see the Azure Docs
public Mono<BlobDownloadAsyncResponse> downloadWithResponse(BlobRange range, DownloadRetryOptions options, BlobRequestConditions accessConditions, boolean rangeGetContentMD5)
BlockBlobClient
, PageBlobClient
, or AppendBlobClient
.
Code Samples
BlobRange
range = newBlobRange
(1024, (long) 2048);DownloadRetryOptions
options = newDownloadRetryOptions
().setMaxRetryRequests(5); client.downloadWithResponse(range, options, null, false).subscribe(response -> {ByteArrayOutputStream
downloadData = newByteArrayOutputStream
(); response.getValue().subscribe(piece -> { try { downloadData.write(piece.array()); } catch (IOException
ex) { throw newUncheckedIOException
(ex); } }); });
For more information, see the Azure Docs
range
- BlobRange
options
- DownloadRetryOptions
accessConditions
- BlobRequestConditions
rangeGetContentMD5
- Whether the contentMD5 for the specified blob range should be returned.public Mono<BlobProperties> downloadToFile(String filePath)
The file will be created and must not exist, if the file already exists a FileAlreadyExistsException
will be thrown.
Uploading data must be done from the BlockBlobClient
, PageBlobClient
, or AppendBlobClient
.
Code Samples
client.downloadToFile(file).subscribe(response -> System
.out.println("Completed download to file"));
For more information, see the Azure Docs
filePath
- A non-null OutputStream
instance where the downloaded data will be written.public Mono<Response<BlobProperties>> downloadToFileWithResponse(String filePath, BlobRange range, ParallelTransferOptions parallelTransferOptions, DownloadRetryOptions options, BlobRequestConditions accessConditions, boolean rangeGetContentMD5)
The file will be created and must not exist, if the file already exists a FileAlreadyExistsException
will be thrown.
Uploading data must be done from the BlockBlobClient
, PageBlobClient
, or AppendBlobClient
.
This method makes an extra HTTP call to get the length of the blob in the beginning. To avoid this extra
call, provide the BlobRange
parameter.
Code Samples
BlobRange
range = newBlobRange
(1024, 2048L);DownloadRetryOptions
options = newDownloadRetryOptions
().setMaxRetryRequests(5); client.downloadToFileWithResponse(file, range, null, options, null, false) .subscribe(response ->System
.out.println("Completed download to file"));
For more information, see the Azure Docs
filePath
- A non-null OutputStream
instance where the downloaded data will be written.range
- BlobRange
parallelTransferOptions
- ParallelTransferOptions
to use to download to file. Number of parallel
transfers parameter is ignored.options
- DownloadRetryOptions
accessConditions
- BlobRequestConditions
rangeGetContentMD5
- Whether the contentMD5 for the specified blob range should be returned.IllegalArgumentException
- If blockSize
is less than 0 or greater than 100MB.UncheckedIOException
- If an I/O error occurs.public Mono<Void> delete()
Code Samples
client.delete().doOnSuccess(response -> System
.out.println("Completed delete"));
For more information, see the Azure Docs
public Mono<Response<Void>> deleteWithResponse(DeleteSnapshotsOptionType deleteBlobSnapshotOptions, BlobRequestConditions accessConditions)
Code Samples
client.deleteWithResponse(DeleteSnapshotsOptionType
.INCLUDE, null) .subscribe(response ->System
.out.printf("Delete completed with status %d%n", response.getStatusCode()));
For more information, see the Azure Docs
deleteBlobSnapshotOptions
- Specifies the behavior for deleting the snapshots on this blob. Include
will delete the base blob and all snapshots. Only
will delete only the snapshots. If a snapshot is being
deleted, you must pass null.accessConditions
- BlobRequestConditions
public Mono<BlobProperties> getProperties()
Code Samples
client.getProperties().subscribe(response ->
System
.out.printf("Type: %s, Size: %d%n", response.getBlobType(), response.getBlobSize()));
For more information, see the Azure Docs
public Mono<Response<BlobProperties>> getPropertiesWithResponse(BlobRequestConditions accessConditions)
Code Samples
BlobRequestConditions
accessConditions = newBlobRequestConditions
().setLeaseId(leaseId); client.getPropertiesWithResponse(accessConditions).subscribe( response ->System
.out.printf("Type: %s, Size: %d%n", response.getValue().getBlobType(), response.getValue().getBlobSize()));
For more information, see the Azure Docs
accessConditions
- BlobRequestConditions
public Mono<Void> setHttpHeaders(BlobHttpHeaders headers)
Code Samples
client.setHttpHeaders(new BlobHttpHeaders
()
.setContentLanguage("en-US")
.setContentType("binary"));
For more information, see the Azure Docs
headers
- BlobHttpHeaders
public Mono<Response<Void>> setHttpHeadersWithResponse(BlobHttpHeaders headers, BlobRequestConditions accessConditions)
Code Samples
BlobRequestConditions
accessConditions = newBlobRequestConditions
().setLeaseId(leaseId); client.setHttpHeadersWithResponse(newBlobHttpHeaders
() .setContentLanguage("en-US") .setContentType("binary"), accessConditions).subscribe( response ->System
.out.printf("Set HTTP headers completed with status %d%n", response.getStatusCode()));
For more information, see the Azure Docs
headers
- BlobHttpHeaders
accessConditions
- BlobRequestConditions
public Mono<Void> setMetadata(Map<String,String> metadata)
Code Samples
client.setMetadata(Collections
.singletonMap("metadata", "value"));
For more information, see the Azure Docs
metadata
- Metadata to associate with the blob.public Mono<Response<Void>> setMetadataWithResponse(Map<String,String> metadata, BlobRequestConditions accessConditions)
Code Samples
BlobRequestConditions
accessConditions = newBlobRequestConditions
().setLeaseId(leaseId); client.setMetadataWithResponse(Collections
.singletonMap("metadata", "value"), accessConditions) .subscribe(response ->System
.out.printf("Set metadata completed with status %d%n", response.getStatusCode()));
For more information, see the Azure Docs
metadata
- Metadata to associate with the blob.accessConditions
- BlobRequestConditions
public Mono<BlobAsyncClientBase> createSnapshot()
Code Samples
client.createSnapshot()
.subscribe(response -> System
.out.printf("Identifier for the snapshot is %s%n",
response.getSnapshotId()));
For more information, see the Azure Docs
BlobAsyncClientBase
which is used to interact with the created snapshot,
use BlobAsyncClientBase.getSnapshotId()
to get the identifier for the snapshot.public Mono<Response<BlobAsyncClientBase>> createSnapshotWithResponse(Map<String,String> metadata, BlobRequestConditions accessConditions)
Code Samples
Map
<String
,String
> snapshotMetadata =Collections
.singletonMap("metadata", "value");BlobRequestConditions
accessConditions = newBlobRequestConditions
().setLeaseId(leaseId); client.createSnapshotWithResponse(snapshotMetadata, accessConditions) .subscribe(response ->System
.out.printf("Identifier for the snapshot is %s%n", response.getValue()));
For more information, see the Azure Docs
metadata
- Metadata to associate with the blob snapshot.accessConditions
- BlobRequestConditions
BlobAsyncClientBase
which is used to interact with the created snapshot,
use BlobAsyncClientBase.getSnapshotId()
to get the identifier for the snapshot.public Mono<Void> setAccessTier(AccessTier tier)
Code Samples
client.setAccessTier(AccessTier
.HOT);
For more information, see the Azure Docs
tier
- The new tier for the blob.NullPointerException
- if tier
is null.public Mono<Response<Void>> setAccessTierWithResponse(AccessTier tier, RehydratePriority priority, String leaseId)
Code Samples
client.setAccessTierWithResponse(AccessTier
.HOT,RehydratePriority
.STANDARD, leaseId) .subscribe(response ->System
.out.printf("Set tier completed with status code %d%n", response.getStatusCode()));
For more information, see the Azure Docs
tier
- The new tier for the blob.priority
- Optional priority to set for re-hydrating blobs.leaseId
- The lease ID the active lease on the blob must match.NullPointerException
- if tier
is null.public Mono<Void> undelete()
Code Samples
client.undelete().doOnSuccess(response -> System
.out.println("Completed undelete"));
For more information, see the Azure Docs
public Mono<Response<Void>> undeleteWithResponse()
Code Samples
client.undeleteWithResponse()
.subscribe(response -> System
.out.printf("Undelete completed with status %d%n", response.getStatusCode()));
For more information, see the Azure Docs
public Mono<StorageAccountInfo> getAccountInfo()
Code Samples
client.getAccountInfo().subscribe(response -> System
.out.printf("Account Kind: %s, SKU: %s%n",
response.getAccountKind(), response.getSkuName()));
For more information, see the Azure Docs
public Mono<Response<StorageAccountInfo>> getAccountInfoWithResponse()
Code Samples
client.getAccountInfoWithResponse().subscribe(response -> System
.out.printf("Account Kind: %s, SKU: %s%n",
response.getValue().getAccountKind(), response.getValue().getSkuName()));
For more information, see the Azure Docs
Copyright © 2019 Microsoft Corporation. All rights reserved.