public class BlobClient extends BlobClientBase
This client is instantiated through BlobClientBuilder
or retrieved via
getBlobClient
.
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.
Modifier and Type | Field and Description |
---|---|
static 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 int |
BLOB_DEFAULT_NUMBER_OF_BUFFERS
The number of buffers to use if none is specied on the buffered upload method.
|
static int |
BLOB_DEFAULT_UPLOAD_BLOCK_SIZE
The block size to use if none is specified in parallel operations.
|
Modifier | Constructor and Description |
---|---|
protected |
BlobClient(BlobAsyncClient client)
Protected constructor for use by
BlobClientBuilder . |
Modifier and Type | Method and Description |
---|---|
AppendBlobClient |
getAppendBlobClient()
Creates a new
AppendBlobClient associated with this blob. |
BlockBlobClient |
getBlockBlobClient()
Creates a new
BlockBlobClient associated with this blob. |
PageBlobClient |
getPageBlobClient()
Creates a new
PageBlobClient associated with this blob. |
BlobClient |
getSnapshotClient(String snapshot)
Creates a new
BlobClient linked to the snapshot of this blob resource. |
BlobClient |
getVersionClient(String versionId)
Creates a new
BlobClient linked to the version of this blob resource. |
void |
upload(InputStream data,
long length)
Creates a new blob.
|
void |
upload(InputStream data,
long length,
boolean overwrite)
Creates a new blob, or updates the content of an existing blob.
|
void |
uploadFromFile(String filePath)
Creates a new block blob.
|
void |
uploadFromFile(String filePath,
boolean overwrite)
Creates a new block blob, or updates the content of an existing block blob.
|
void |
uploadFromFile(String filePath,
ParallelTransferOptions parallelTransferOptions,
BlobHttpHeaders headers,
Map<String,String> metadata,
AccessTier tier,
BlobRequestConditions requestConditions,
Duration timeout)
Creates a new block blob, or updates the content of an existing block blob.
|
com.azure.core.http.rest.Response<BlockBlobItem> |
uploadFromFileWithResponse(BlobUploadFromFileOptions options,
Duration timeout,
com.azure.core.util.Context context)
Creates a new block blob, or updates the content of an existing block blob.
|
com.azure.core.http.rest.Response<BlockBlobItem> |
uploadWithResponse(BlobParallelUploadOptions options,
com.azure.core.util.Context context)
|
com.azure.core.http.rest.Response<BlockBlobItem> |
uploadWithResponse(BlobParallelUploadOptions options,
Duration timeout,
com.azure.core.util.Context context)
Creates a new blob, or updates the content of an existing blob.
|
void |
uploadWithResponse(InputStream data,
long length,
ParallelTransferOptions parallelTransferOptions,
BlobHttpHeaders headers,
Map<String,String> metadata,
AccessTier tier,
BlobRequestConditions requestConditions,
Duration timeout,
com.azure.core.util.Context context)
Creates a new blob, or updates the content of an existing blob.
|
abortCopyFromUrl, abortCopyFromUrlWithResponse, beginCopy, beginCopy, beginCopy, copyFromUrl, copyFromUrlWithResponse, copyFromUrlWithResponse, createSnapshot, createSnapshotWithResponse, delete, deleteWithResponse, download, downloadToFile, downloadToFile, downloadToFileWithResponse, downloadToFileWithResponse, downloadToFileWithResponse, downloadWithResponse, exists, existsWithResponse, generateSas, generateUserDelegationSas, getAccountInfo, getAccountInfoWithResponse, getAccountName, getBlobName, getBlobUrl, getContainerName, getCustomerProvidedKey, getHttpPipeline, getProperties, getPropertiesWithResponse, getServiceVersion, getSnapshotId, getTags, getTagsWithResponse, getVersionId, isSnapshot, openInputStream, openInputStream, openInputStream, openQueryInputStream, openQueryInputStreamWithResponse, query, queryWithResponse, setAccessTier, setAccessTierWithResponse, setAccessTierWithResponse, setHttpHeaders, setHttpHeadersWithResponse, setMetadata, setMetadataWithResponse, setTags, setTagsWithResponse, undelete, undeleteWithResponse
public static final int BLOB_DEFAULT_UPLOAD_BLOCK_SIZE
public static final int BLOB_DEFAULT_NUMBER_OF_BUFFERS
public static final int BLOB_DEFAULT_HTBB_UPLOAD_BLOCK_SIZE
protected BlobClient(BlobAsyncClient client)
BlobClientBuilder
.client
- the async blob clientpublic BlobClient getSnapshotClient(String snapshot)
BlobClient
linked to the snapshot
of this blob resource.getSnapshotClient
in class BlobClientBase
snapshot
- the identifier for a specific snapshot of this blobBlobClient
used to interact with the specific snapshot.public BlobClient getVersionClient(String versionId)
BlobClient
linked to the version
of this blob resource.getVersionClient
in class BlobClientBase
versionId
- the identifier for a specific version of this blob,
pass null
to interact with the latest blob version.BlobClient
used to interact with the specific version.public AppendBlobClient getAppendBlobClient()
AppendBlobClient
associated with this blob.AppendBlobClient
associated with this blob.public BlockBlobClient getBlockBlobClient()
BlockBlobClient
associated with this blob.BlockBlobClient
associated with this blob.public PageBlobClient getPageBlobClient()
PageBlobClient
associated with this blob.PageBlobClient
associated with this blob.public void upload(InputStream data, long length)
data
- The data to write to the blob. The data must be markable. This is in order to support retries. If
the data is not markable, consider opening a BlobOutputStream
and
writing to the returned stream. Alternatively, consider wrapping your data source in a
BufferedInputStream
to add mark support.length
- The exact length of the data. It is important that this value match precisely the length of the
data provided in the InputStream
.public void upload(InputStream data, long length, boolean overwrite)
data
- The data to write to the blob. The data must be markable. This is in order to support retries. If
the data is not markable, consider opening a BlobOutputStream
and
writing to the returned stream. Alternatively, consider wrapping your data source in a
BufferedInputStream
to add mark support.length
- The exact length of the data. It is important that this value match precisely the length of the
data provided in the InputStream
.overwrite
- Whether or not to overwrite, should data exist on the blob.public void uploadWithResponse(InputStream data, long length, ParallelTransferOptions parallelTransferOptions, BlobHttpHeaders headers, Map<String,String> metadata, AccessTier tier, BlobRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context)
To avoid overwriting, pass "*" to BlobRequestConditions.setIfNoneMatch(String)
.
data
- The data to write to the blob. The data must be markable. This is in order to support retries. If
the data is not markable, consider opening a BlobOutputStream
and
writing to the returned stream. Alternatively, consider wrapping your data source in a
BufferedInputStream
to add mark support.length
- The exact length of the data. It is important that this value match precisely the length of the
data provided in the InputStream
.parallelTransferOptions
- ParallelTransferOptions
used to configure buffered uploading.headers
- BlobHttpHeaders
metadata
- Metadata to associate with the blob.tier
- AccessTier
for the destination blob.requestConditions
- BlobRequestConditions
timeout
- An optional timeout value beyond which a RuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.@Deprecated public com.azure.core.http.rest.Response<BlockBlobItem> uploadWithResponse(BlobParallelUploadOptions options, com.azure.core.util.Context context)
To avoid overwriting, pass "*" to BlobRequestConditions.setIfNoneMatch(String)
.
options
- BlobParallelUploadOptions
context
- Additional context that is passed through the Http pipeline during the service call.public com.azure.core.http.rest.Response<BlockBlobItem> uploadWithResponse(BlobParallelUploadOptions options, Duration timeout, com.azure.core.util.Context context)
To avoid overwriting, pass "*" to BlobRequestConditions.setIfNoneMatch(String)
.
options
- BlobParallelUploadOptions
timeout
- An optional timeout value beyond which a RuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.public void uploadFromFile(String filePath)
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()); }
filePath
- Path of the file to uploadUncheckedIOException
- If an I/O error occurspublic void uploadFromFile(String filePath, boolean overwrite)
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()); }
filePath
- Path of the file to uploadoverwrite
- Whether or not to overwrite, should the blob already existUncheckedIOException
- If an I/O error occurspublic void uploadFromFile(String filePath, ParallelTransferOptions parallelTransferOptions, BlobHttpHeaders headers, Map<String,String> metadata, AccessTier tier, BlobRequestConditions requestConditions, Duration timeout)
To avoid overwriting, pass "*" to BlobRequestConditions.setIfNoneMatch(String)
.
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()); }
filePath
- Path of the file to uploadparallelTransferOptions
- 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 uploaded blobrequestConditions
- BlobRequestConditions
timeout
- An optional timeout value beyond which a RuntimeException
will be raised.UncheckedIOException
- If an I/O error occurspublic com.azure.core.http.rest.Response<BlockBlobItem> uploadFromFileWithResponse(BlobUploadFromFileOptions options, Duration timeout, com.azure.core.util.Context context)
To avoid overwriting, pass "*" to BlobRequestConditions.setIfNoneMatch(String)
.
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()); }
options
- BlobUploadFromFileOptions
timeout
- An optional timeout value beyond which a RuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.UncheckedIOException
- If an I/O error occursCopyright © 2020 Microsoft Corporation. All rights reserved.