你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
BlobClient Class
- java.
lang. Object - com.
azure. storage. blob. specialized. BlobClientBase - com.
azure. storage. blob. BlobClient
- com.
- com.
public class BlobClient
extends BlobClientBase
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 getBlobClient(String blobName).
For operations on a specific blob type (i.e append, block, or page) use getAppendBlobClient(), getBlockBlobClient(), or getPageBlobClient() to construct a client that allows blob specific operations.
Please refer to the Azure Docs for more information.
Field Summary
Modifier and Type | Field and Description |
---|---|
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. |
static final int |
BLOB_DEFAULT_NUMBER_OF_BUFFERS
The number of buffers to use if none is specified on the buffered upload method. |
static final int |
BLOB_DEFAULT_UPLOAD_BLOCK_SIZE
The block size to use if none is specified in parallel operations. |
Constructor Summary
Modifier | Constructor | Description |
---|---|---|
protected | BlobClient(BlobAsyncClient client) |
Protected constructor for use by BlobClientBuilder. |
protected | BlobClient(BlobAsyncClient client, 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. |
Method Summary
Methods inherited from BlobClientBase
Methods inherited from java.lang.Object
Field Details
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.
BLOB_DEFAULT_NUMBER_OF_BUFFERS
public static final int BLOB_DEFAULT_NUMBER_OF_BUFFERS
The number of buffers to use if none is specified on the buffered upload method.
BLOB_DEFAULT_UPLOAD_BLOCK_SIZE
public static final int BLOB_DEFAULT_UPLOAD_BLOCK_SIZE
The block size to use if none is specified in parallel operations.
Constructor Details
BlobClient
protected BlobClient(BlobAsyncClient client)
Protected constructor for use by BlobClientBuilder.
Parameters:
BlobClient
protected BlobClient(BlobAsyncClient client, 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:
null
to interact with the blob directly.
null
to allow the service to use its own encryption.
null
to allow the service to use its own encryption.
null
to interact with the latest blob version.
Method Details
getAppendBlobClient
public AppendBlobClient getAppendBlobClient()
Creates a new AppendBlobClient associated with this blob.
Returns:
getBlockBlobClient
public BlockBlobClient getBlockBlobClient()
Creates a new BlockBlobClient associated with this blob.
Returns:
getCustomerProvidedKeyClient
public BlobClient getCustomerProvidedKeyClient(CustomerProvidedKey customerProvidedKey)
Creates a new BlobClient with the specified customerProvidedKey
.
Overrides:
BlobClient.getCustomerProvidedKeyClient(CustomerProvidedKey customerProvidedKey)Parameters:
null
to use no customer provided key.
Returns:
customerProvidedKey
.getEncryptionScopeClient
public BlobClient getEncryptionScopeClient(String encryptionScope)
Creates a new BlobClient with the specified encryptionScope
.
Overrides:
BlobClient.getEncryptionScopeClient(String encryptionScope)Parameters:
null
to use no encryption scope.
Returns:
encryptionScope
.getPageBlobClient
public PageBlobClient getPageBlobClient()
Creates a new PageBlobClient associated with this blob.
Returns:
getSnapshotClient
public BlobClient getSnapshotClient(String snapshot)
Creates a new BlobClient linked to the snapshot
of this blob resource.
Overrides:
BlobClient.getSnapshotClient(String snapshot)Parameters:
Returns:
getVersionClient
public BlobClient getVersionClient(String versionId)
Creates a new BlobClient linked to the version
of this blob resource.
Overrides:
BlobClient.getVersionClient(String versionId)Parameters:
null
to interact with the latest blob version.
Returns:
upload
public void upload(BinaryData data)
Creates a new blob. By default this method will not overwrite an existing blob.
Parameters:
upload
public void upload(BinaryData data, boolean overwrite)
Creates a new blob, or updates the content of an existing blob.
Parameters:
upload
public void upload(InputStream data)
Creates a new blob. By default this method will not overwrite an existing blob.
Parameters:
upload
public void upload(InputStream data, boolean overwrite)
Creates a new blob, or updates the content of an existing blob.
Parameters:
upload
public void upload(InputStream data, long length)
Creates a new blob. By default this method will not overwrite an existing blob.
Parameters:
upload
public void upload(InputStream data, long length, boolean overwrite)
Creates a new blob, or updates the content of an existing blob.
Parameters:
uploadFromFile
public void uploadFromFile(String filePath)
Creates a new block blob. By default this method will not overwrite an existing blob.
Code Samples
try {
client.uploadFromFile(filePath);
System.out.println("Upload from file succeeded");
} catch (UncheckedIOException ex) {
System.err.printf("Failed to upload from file %s%n", ex.getMessage());
}
Parameters:
uploadFromFile
public void uploadFromFile(String filePath, boolean overwrite)
Creates a new block blob, or updates the content of an existing block blob.
Code Samples
try {
boolean overwrite = false;
client.uploadFromFile(filePath, overwrite);
System.out.println("Upload from file succeeded");
} catch (UncheckedIOException ex) {
System.err.printf("Failed to upload from file %s%n", ex.getMessage());
}
Parameters:
uploadFromFile
public void uploadFromFile(String filePath, ParallelTransferOptions parallelTransferOptions, BlobHttpHeaders headers, Map
Creates a new block blob, or updates the content of an existing block blob.
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));
Long blockSize = 100L * 1024L * 1024L; // 100 MB;
ParallelTransferOptions parallelTransferOptions = new ParallelTransferOptions().setBlockSizeLong(blockSize);
try {
client.uploadFromFile(filePath, parallelTransferOptions, headers, metadata,
AccessTier.HOT, requestConditions, timeout);
System.out.println("Upload from file succeeded");
} catch (UncheckedIOException ex) {
System.err.printf("Failed to upload from file %s%n", ex.getMessage());
}
Parameters:
uploadFromFileWithResponse
public Response
Creates a new block blob, or updates the content of an existing block blob.
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));
Long blockSize = 100 * 1024 * 1024L; // 100 MB;
ParallelTransferOptions parallelTransferOptions = new ParallelTransferOptions().setBlockSizeLong(blockSize);
try {
client.uploadFromFileWithResponse(new BlobUploadFromFileOptions(filePath)
.setParallelTransferOptions(parallelTransferOptions).setHeaders(headers).setMetadata(metadata)
.setTags(tags).setTier(AccessTier.HOT).setRequestConditions(requestConditions), timeout,
new Context(key2, value2));
System.out.println("Upload from file succeeded");
} catch (UncheckedIOException ex) {
System.err.printf("Failed to upload from file %s%n", ex.getMessage());
}
Parameters:
Returns:
uploadWithResponse
@Deprecated
public Response
Deprecated
Creates a new blob, or updates the content of an existing blob.
To avoid overwriting, pass "*" to setIfNoneMatch(String ifNoneMatch).
Parameters:
Returns:
uploadWithResponse
public Response
Creates a new blob, or updates the content of an existing blob.
To avoid overwriting, pass "*" to setIfNoneMatch(String ifNoneMatch).
Parameters:
Returns:
uploadWithResponse
@Deprecated
public void uploadWithResponse(InputStream data, long length, ParallelTransferOptions parallelTransferOptions, BlobHttpHeaders headers, Map
Deprecated
Creates a new blob, or updates the content of an existing blob.
To avoid overwriting, pass "*" to setIfNoneMatch(String ifNoneMatch).
Parameters: