azure-storage-blobs
Public Member Functions | Static Public Member Functions | Friends | List of all members
Azure::Storage::Blobs::BlockBlobClient Class Reference

The BlockBlobClient allows you to manipulate Azure Storage block blobs. More...

#include <block_blob_client.hpp>

Inheritance diagram for Azure::Storage::Blobs::BlockBlobClient:
Azure::Storage::Blobs::BlobClient

Public Member Functions

 BlockBlobClient (const std::string &blobUri, std::shared_ptr< SharedKeyCredential > credential, const BlockBlobClientOptions &options=BlockBlobClientOptions())
 Initialize a new instance of BlockBlobClient. More...
 
 BlockBlobClient (const std::string &blobUri, std::shared_ptr< Core::Credentials::ClientSecretCredential > credential, const BlockBlobClientOptions &options=BlockBlobClientOptions())
 Initialize a new instance of BlockBlobClient. More...
 
 BlockBlobClient (const std::string &blobUri, const BlockBlobClientOptions &options=BlockBlobClientOptions())
 Initialize a new instance of BlockBlobClient. More...
 
BlockBlobClient WithSnapshot (const std::string &snapshot) const
 Initializes a new instance of the BlockBlobClient class with an identical uri source but the specified snapshot timestamp. More...
 
BlockBlobClient WithVersionId (const std::string &versionId) const
 Creates a clone of this instance that references a version ID rather than the base blob. More...
 
Azure::Core::Response< UploadBlockBlobResultUpload (Azure::Core::Http::BodyStream *content, const UploadBlockBlobOptions &options=UploadBlockBlobOptions()) const
 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. More...
 
Azure::Core::Response< UploadBlockBlobFromResultUploadFrom (const uint8_t *buffer, std::size_t bufferSize, const UploadBlockBlobFromOptions &options=UploadBlockBlobFromOptions()) const
 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. More...
 
Azure::Core::Response< UploadBlockBlobFromResultUploadFrom (const std::string &file, const UploadBlockBlobFromOptions &options=UploadBlockBlobFromOptions()) const
 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. More...
 
Azure::Core::Response< StageBlockResultStageBlock (const std::string &blockId, Azure::Core::Http::BodyStream *content, const StageBlockOptions &options=StageBlockOptions()) const
 Creates a new block as part of a block blob's staging area to be eventually committed via the CommitBlockList operation. More...
 
Azure::Core::Response< StageBlockFromUriResultStageBlockFromUri (const std::string &blockId, const std::string &sourceUri, const StageBlockFromUriOptions &options=StageBlockFromUriOptions()) const
 Creates a new block to be committed as part of a blob where the contents are read from the sourceUri. More...
 
Azure::Core::Response< CommitBlockListResultCommitBlockList (const std::vector< std::pair< BlockType, std::string >> &blockIds, const CommitBlockListOptions &options=CommitBlockListOptions()) const
 Writes a blob by specifying the list of block IDs that make up the blob. In order to be written as part of a blob, a block must have been successfully written to the server in a prior StageBlock operation. You can call CommitBlockList to update a blob by uploading only those blocks that have changed, then committing the new and existing blocks together. You can do this by specifying whether to commit a block from the committed block list or from the uncommitted block list, or to commit the most recently uploaded version of the block, whichever list it may belong to. More...
 
Azure::Core::Response< GetBlockListResultGetBlockList (const GetBlockListOptions &options=GetBlockListOptions()) const
 Retrieves the list of blocks that have been uploaded as part of a block blob. There are two block lists maintained for a blob. The Committed Block list has blocks that have been successfully committed to a given blob with CommitBlockList. The Uncommitted Block list has blocks that have been uploaded for a blob using StageBlock, but that have not yet been committed. More...
 
- Public Member Functions inherited from Azure::Storage::Blobs::BlobClient
 BlobClient (const std::string &blobUri, std::shared_ptr< SharedKeyCredential > credential, const BlobClientOptions &options=BlobClientOptions())
 Initialize a new instance of BlobClient. More...
 
 BlobClient (const std::string &blobUri, std::shared_ptr< Core::Credentials::ClientSecretCredential > credential, const BlobClientOptions &options=BlobClientOptions())
 Initialize a new instance of BlobClient. More...
 
 BlobClient (const std::string &blobUri, const BlobClientOptions &options=BlobClientOptions())
 Initialize a new instance of BlobClient. More...
 
BlockBlobClient GetBlockBlobClient () const
 Creates a new BlockBlobClient object with the same uri as this BlobClient. The new BlockBlobClient uses the same request policy pipeline as this BlobClient. More...
 
AppendBlobClient GetAppendBlobClient () const
 Creates a new AppendBlobClient object with the same uri as this BlobClient. The new AppendBlobClient uses the same request policy pipeline as this BlobClient. More...
 
PageBlobClient GetPageBlobClient () const
 Creates a new PageBlobClient object with the same uri as this BlobClient. The new PageBlobClient uses the same request policy pipeline as this BlobClient. More...
 
std::string GetUri () const
 Gets the blob's primary uri endpoint. More...
 
BlobClient WithSnapshot (const std::string &snapshot) const
 Initializes a new instance of the BlobClient class with an identical uri source but the specified snapshot timestamp. More...
 
BlobClient WithVersionId (const std::string &versionId) const
 Creates a clone of this instance that references a version ID rather than the base blob. More...
 
Azure::Core::Response< GetBlobPropertiesResultGetProperties (const GetBlobPropertiesOptions &options=GetBlobPropertiesOptions()) const
 Returns all user-defined metadata, standard HTTP properties, and system properties for the blob. It does not return the content of the blob. More...
 
Azure::Core::Response< SetBlobHttpHeadersResultSetHttpHeaders (BlobHttpHeaders httpHeaders, const SetBlobHttpHeadersOptions &options=SetBlobHttpHeadersOptions()) const
 Sets system properties on the blob. More...
 
Azure::Core::Response< SetBlobMetadataResultSetMetadata (std::map< std::string, std::string > metadata, const SetBlobMetadataOptions &options=SetBlobMetadataOptions()) const
 Sets user-defined metadata for the specified blob as one or more name-value pairs. More...
 
Azure::Core::Response< SetBlobAccessTierResultSetAccessTier (AccessTier Tier, const SetBlobAccessTierOptions &options=SetBlobAccessTierOptions()) const
 Sets the tier on a blob. The operation is allowed on a page blob in a premium storage account and on a block blob in a blob storage or general purpose v2 account. More...
 
Azure::Core::Response< StartCopyBlobFromUriResultStartCopyFromUri (const std::string &sourceUri, const StartCopyBlobFromUriOptions &options=StartCopyBlobFromUriOptions()) const
 Copies data at from the source to this blob. More...
 
Azure::Core::Response< AbortCopyBlobFromUriResultAbortCopyFromUri (const std::string &copyId, const AbortCopyBlobFromUriOptions &options=AbortCopyBlobFromUriOptions()) const
 Aborts a pending StartCopyFromUri operation, and leaves this blob with zero length and full metadata. More...
 
Azure::Core::Response< DownloadBlobResultDownload (const DownloadBlobOptions &options=DownloadBlobOptions()) const
 Downloads a blob or a blob range from the service, including its metadata and properties. More...
 
Azure::Core::Response< DownloadBlobToResultDownloadTo (uint8_t *buffer, std::size_t bufferSize, const DownloadBlobToOptions &options=DownloadBlobToOptions()) const
 Downloads a blob or a blob range from the service to a memory buffer using parallel requests. More...
 
Azure::Core::Response< DownloadBlobToResultDownloadTo (const std::string &file, const DownloadBlobToOptions &options=DownloadBlobToOptions()) const
 Downloads a blob or a blob range from the service to a file using parallel requests. More...
 
Azure::Core::Response< CreateBlobSnapshotResultCreateSnapshot (const CreateBlobSnapshotOptions &options=CreateBlobSnapshotOptions()) const
 Creates a read-only snapshot of a blob. More...
 
Azure::Core::Response< DeleteBlobResultDelete (const DeleteBlobOptions &options=DeleteBlobOptions()) const
 Marks the specified blob or snapshot for deletion. The blob is later deleted during garbage collection. Note that in order to delete a blob, you must delete all of its snapshots. You can delete both at the same time using DeleteBlobOptions.DeleteSnapshots. More...
 
Azure::Core::Response< UndeleteBlobResultUndelete (const UndeleteBlobOptions &options=UndeleteBlobOptions()) const
 Restores the contents and metadata of a soft deleted blob and any associated soft deleted snapshots. More...
 
Azure::Core::Response< AcquireBlobLeaseResultAcquireLease (const std::string &proposedLeaseId, int32_t duration, const AcquireBlobLeaseOptions &options=AcquireBlobLeaseOptions()) const
 Acquires a lease on the blob. More...
 
Azure::Core::Response< RenewBlobLeaseResultRenewLease (const std::string &leaseId, const RenewBlobLeaseOptions &options=RenewBlobLeaseOptions()) const
 Renews the blob's previously-acquired lease. More...
 
Azure::Core::Response< ReleaseBlobLeaseResultReleaseLease (const std::string &leaseId, const ReleaseBlobLeaseOptions &options=ReleaseBlobLeaseOptions()) const
 Releases the blob's previously-acquired lease. More...
 
Azure::Core::Response< ChangeBlobLeaseResultChangeLease (const std::string &leaseId, const std::string &proposedLeaseId, const ChangeBlobLeaseOptions &options=ChangeBlobLeaseOptions()) const
 Changes the lease of an active lease. More...
 
Azure::Core::Response< BreakBlobLeaseResultBreakLease (const BreakBlobLeaseOptions &options=BreakBlobLeaseOptions()) const
 Breaks the previously-acquired lease. More...
 
Azure::Core::Response< SetBlobTagsResultSetTags (std::map< std::string, std::string > tags, const SetBlobTagsOptions &options=SetBlobTagsOptions()) const
 Sets tags on the underlying blob. More...
 
Azure::Core::Response< GetBlobTagsResultGetTags (const GetBlobTagsOptions &options=GetBlobTagsOptions()) const
 Gets the tags associated with the underlying blob. More...
 

Static Public Member Functions

static BlockBlobClient CreateFromConnectionString (const std::string &connectionString, const std::string &containerName, const std::string &blobName, const BlockBlobClientOptions &options=BlockBlobClientOptions())
 Initialize a new instance of BlockBlobClient. More...
 
- Static Public Member Functions inherited from Azure::Storage::Blobs::BlobClient
static BlobClient CreateFromConnectionString (const std::string &connectionString, const std::string &containerName, const std::string &blobName, const BlobClientOptions &options=BlobClientOptions())
 Initialize a new instance of BlobClient. More...
 

Friends

class BlobClient
 
class Files::DataLake::FileClient
 

Additional Inherited Members

- Protected Attributes inherited from Azure::Storage::Blobs::BlobClient
Azure::Core::Http::Url m_blobUrl
 
std::shared_ptr< Azure::Core::Http::HttpPipeline > m_pipeline
 
Azure::Core::Nullable< EncryptionKeym_customerProvidedKey
 
Azure::Core::Nullable< std::string > m_encryptionScope
 

Detailed Description

The BlockBlobClient allows you to manipulate Azure Storage block blobs.

Block blobs let you upload large blobs efficiently. Block blobs are comprised of blocks, each of which is identified by a block ID. You create or modify a block blob by writing a set of blocks and committing them by their block IDs. Each block can be a different size.

When you upload a block to a blob in your storage account, it is associated with the specified block blob, but it does not become part of the blob until you commit a list of blocks that includes the new block's ID. New blocks remain in an uncommitted state until they are specifically committed or discarded. Writing a block does not update the last modified time of an existing blob.

Constructor & Destructor Documentation

◆ BlockBlobClient() [1/3]

Azure::Storage::Blobs::BlockBlobClient::BlockBlobClient ( const std::string &  blobUri,
std::shared_ptr< SharedKeyCredential >  credential,
const BlockBlobClientOptions options = BlockBlobClientOptions() 
)
explicit

Initialize a new instance of BlockBlobClient.

Parameters
blobUriA uri referencing the blob that includes the name of the account, the name of the container, and the name of the blob.
credentialThe shared key credential used to sign requests.
optionsOptional client options that define the transport pipeline policies for authentication, retries, etc., that are applied to every request.
29  : BlobClient(blobUri, std::move(credential), options)
30  {
31  }

◆ BlockBlobClient() [2/3]

Azure::Storage::Blobs::BlockBlobClient::BlockBlobClient ( const std::string &  blobUri,
std::shared_ptr< Core::Credentials::ClientSecretCredential >  credential,
const BlockBlobClientOptions options = BlockBlobClientOptions() 
)
explicit

Initialize a new instance of BlockBlobClient.

Parameters
blobUriA uri referencing the blob that includes the name of the account, the name of the container, and the name of the blob.
credentialThe client secret credential used to sign requests.
optionsOptional client options that define the transport pipeline policies for authentication, retries, etc., that are applied to every request.
37  : BlobClient(blobUri, std::move(credential), options)
38  {
39  }

◆ BlockBlobClient() [3/3]

Azure::Storage::Blobs::BlockBlobClient::BlockBlobClient ( const std::string &  blobUri,
const BlockBlobClientOptions options = BlockBlobClientOptions() 
)
explicit

Initialize a new instance of BlockBlobClient.

Parameters
blobUriA uri referencing the blob that includes the name of the account, the name of the container, and the name of the blob, and possibly also a SAS token.
optionsOptional client options that define the transport pipeline policies for authentication, retries, etc., that are applied to every request.
44  : BlobClient(blobUri, options)
45  {
46  }

Member Function Documentation

◆ CommitBlockList()

Azure::Core::Response< CommitBlockListResult > Azure::Storage::Blobs::BlockBlobClient::CommitBlockList ( const std::vector< std::pair< BlockType, std::string >> &  blockIds,
const CommitBlockListOptions options = CommitBlockListOptions() 
) const

Writes a blob by specifying the list of block IDs that make up the blob. In order to be written as part of a blob, a block must have been successfully written to the server in a prior StageBlock operation. You can call CommitBlockList to update a blob by uploading only those blocks that have changed, then committing the new and existing blocks together. You can do this by specifying whether to commit a block from the committed block list or from the uncommitted block list, or to commit the most recently uploaded version of the block, whichever list it may belong to.

Parameters
blockIdsBase64 encoded block IDs to indicate that make up the blob.
optionsOptional parameters to execute this function.
Returns
A CommitBlobBlockListResult describing the state of the updated block blob.
328  {
329  BlobRestClient::BlockBlob::CommitBlockListOptions protocolLayerOptions;
330  protocolLayerOptions.BlockList = blockIds;
331  protocolLayerOptions.HttpHeaders = options.HttpHeaders;
332  protocolLayerOptions.Metadata = options.Metadata;
333  protocolLayerOptions.Tier = options.Tier;
334  protocolLayerOptions.LeaseId = options.AccessConditions.LeaseId;
335  protocolLayerOptions.IfModifiedSince = options.AccessConditions.IfModifiedSince;
336  protocolLayerOptions.IfUnmodifiedSince = options.AccessConditions.IfUnmodifiedSince;
337  protocolLayerOptions.IfMatch = options.AccessConditions.IfMatch;
338  protocolLayerOptions.IfNoneMatch = options.AccessConditions.IfNoneMatch;
339  protocolLayerOptions.IfTags = options.AccessConditions.TagConditions;
340  if (m_customerProvidedKey.HasValue())
341  {
342  protocolLayerOptions.EncryptionKey = m_customerProvidedKey.GetValue().Key;
343  protocolLayerOptions.EncryptionKeySha256 = m_customerProvidedKey.GetValue().KeyHash;
344  protocolLayerOptions.EncryptionAlgorithm = m_customerProvidedKey.GetValue().Algorithm;
345  }
346  protocolLayerOptions.EncryptionScope = m_encryptionScope;
347  return BlobRestClient::BlockBlob::CommitBlockList(
348  options.Context, *m_pipeline, m_blobUrl, protocolLayerOptions);
349  }

◆ CreateFromConnectionString()

BlockBlobClient Azure::Storage::Blobs::BlockBlobClient::CreateFromConnectionString ( const std::string &  connectionString,
const std::string &  containerName,
const std::string &  blobName,
const BlockBlobClientOptions options = BlockBlobClientOptions() 
)
static

Initialize a new instance of BlockBlobClient.

Parameters
connectionStringA connection string includes the authentication information required for your application to access data in an Azure Storage account at runtime.
containerNameThe name of the container containing this blob.
blobNameThe name of this blob.
optionsOptional client options that define the transport pipeline policies for authentication, retries, etc., that are applied to every request.
Returns
A new BlockBlobClient instance.
19  {
20  BlockBlobClient newClient(
21  BlobClient::CreateFromConnectionString(connectionString, containerName, blobName, options));
22  return newClient;
23  }

◆ GetBlockList()

Azure::Core::Response< GetBlockListResult > Azure::Storage::Blobs::BlockBlobClient::GetBlockList ( const GetBlockListOptions options = GetBlockListOptions()) const

Retrieves the list of blocks that have been uploaded as part of a block blob. There are two block lists maintained for a blob. The Committed Block list has blocks that have been successfully committed to a given blob with CommitBlockList. The Uncommitted Block list has blocks that have been uploaded for a blob using StageBlock, but that have not yet been committed.

Parameters
optionsOptional parameters to execute this function.
Returns
A GetBlobBlockListResult describing requested block list.
353  {
354  BlobRestClient::BlockBlob::GetBlockListOptions protocolLayerOptions;
355  protocolLayerOptions.ListType = options.ListType;
356  protocolLayerOptions.LeaseId = options.AccessConditions.LeaseId;
357  protocolLayerOptions.IfTags = options.AccessConditions.TagConditions;
358  return BlobRestClient::BlockBlob::GetBlockList(
359  options.Context, *m_pipeline, m_blobUrl, protocolLayerOptions);
360  }

◆ StageBlock()

Azure::Core::Response< StageBlockResult > Azure::Storage::Blobs::BlockBlobClient::StageBlock ( const std::string &  blockId,
Azure::Core::Http::BodyStream *  content,
const StageBlockOptions options = StageBlockOptions() 
) const

Creates a new block as part of a block blob's staging area to be eventually committed via the CommitBlockList operation.

Parameters
blockIdA valid Base64 string value that identifies the block. Prior to encoding, the string must be less than or equal to 64 bytes in size.
contentA BodyStream containing the content to upload.
optionsOptional parameters to execute this function.
Returns
A StageBlockResult describing the state of the updated block.
269  {
270  BlobRestClient::BlockBlob::StageBlockOptions protocolLayerOptions;
271  protocolLayerOptions.BlockId = blockId;
272  protocolLayerOptions.TransactionalContentMd5 = options.TransactionalContentMd5;
273  protocolLayerOptions.TransactionalContentCrc64 = options.TransactionalContentCrc64;
274  protocolLayerOptions.LeaseId = options.AccessConditions.LeaseId;
275  if (m_customerProvidedKey.HasValue())
276  {
277  protocolLayerOptions.EncryptionKey = m_customerProvidedKey.GetValue().Key;
278  protocolLayerOptions.EncryptionKeySha256 = m_customerProvidedKey.GetValue().KeyHash;
279  protocolLayerOptions.EncryptionAlgorithm = m_customerProvidedKey.GetValue().Algorithm;
280  }
281  protocolLayerOptions.EncryptionScope = m_encryptionScope;
282  return BlobRestClient::BlockBlob::StageBlock(
283  options.Context, *m_pipeline, m_blobUrl, content, protocolLayerOptions);
284  }

◆ StageBlockFromUri()

Azure::Core::Response< StageBlockFromUriResult > Azure::Storage::Blobs::BlockBlobClient::StageBlockFromUri ( const std::string &  blockId,
const std::string &  sourceUri,
const StageBlockFromUriOptions options = StageBlockFromUriOptions() 
) const

Creates a new block to be committed as part of a blob where the contents are read from the sourceUri.

Parameters
blockIdA valid Base64 string value that identifies the block. Prior to encoding, the string must be less than or equal to 64 bytes in size.
sourceUriSpecifies the uri of the source blob. The value may be a uri of up to 2 KB in length that specifies a blob. The source blob must either be public or must be authenticated via a shared access signature. If the source blob is public, no authentication is required to perform the operation.
optionsOptional parameters to execute this function.
Returns
A StageBlockFromUriResult describing the state of the updated block blob.
290  {
291  BlobRestClient::BlockBlob::StageBlockFromUriOptions protocolLayerOptions;
292  protocolLayerOptions.BlockId = blockId;
293  protocolLayerOptions.SourceUri = sourceUri;
294  if (options.SourceOffset.HasValue() && options.SourceLength.HasValue())
295  {
296  protocolLayerOptions.SourceRange = std::make_pair(
297  options.SourceOffset.GetValue(),
298  options.SourceOffset.GetValue() + options.SourceLength.GetValue() - 1);
299  }
300  else if (options.SourceOffset.HasValue())
301  {
302  protocolLayerOptions.SourceRange = std::make_pair(
303  options.SourceOffset.GetValue(),
304  std::numeric_limits<
305  std::remove_reference_t<decltype(options.SourceOffset.GetValue())>>::max());
306  }
307  protocolLayerOptions.TransactionalContentMd5 = options.TransactionalContentMd5;
308  protocolLayerOptions.TransactionalContentCrc64 = options.TransactionalContentCrc64;
309  protocolLayerOptions.LeaseId = options.AccessConditions.LeaseId;
310  protocolLayerOptions.SourceIfModifiedSince = options.SourceConditions.IfModifiedSince;
311  protocolLayerOptions.SourceIfUnmodifiedSince = options.SourceConditions.IfUnmodifiedSince;
312  protocolLayerOptions.SourceIfMatch = options.SourceConditions.IfMatch;
313  protocolLayerOptions.SourceIfNoneMatch = options.SourceConditions.IfNoneMatch;
314  if (m_customerProvidedKey.HasValue())
315  {
316  protocolLayerOptions.EncryptionKey = m_customerProvidedKey.GetValue().Key;
317  protocolLayerOptions.EncryptionKeySha256 = m_customerProvidedKey.GetValue().KeyHash;
318  protocolLayerOptions.EncryptionAlgorithm = m_customerProvidedKey.GetValue().Algorithm;
319  }
320  protocolLayerOptions.EncryptionScope = m_encryptionScope;
321  return BlobRestClient::BlockBlob::StageBlockFromUri(
322  options.Context, *m_pipeline, m_blobUrl, protocolLayerOptions);
323  }

◆ Upload()

Azure::Core::Response< UploadBlockBlobResult > Azure::Storage::Blobs::BlockBlobClient::Upload ( Azure::Core::Http::BodyStream *  content,
const UploadBlockBlobOptions options = UploadBlockBlobOptions() 
) const

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.

Parameters
contentA BodyStream containing the content to upload.
optionsOptional parameters to execute this function.
Returns
A UploadBlockBlobResult describing the state of the updated block blob.
81  {
82  BlobRestClient::BlockBlob::UploadBlockBlobOptions protocolLayerOptions;
83  protocolLayerOptions.TransactionalContentMd5 = options.TransactionalContentMd5;
84  protocolLayerOptions.TransactionalContentCrc64 = options.TransactionalContentCrc64;
85  protocolLayerOptions.HttpHeaders = options.HttpHeaders;
86  protocolLayerOptions.Metadata = options.Metadata;
87  protocolLayerOptions.Tier = options.Tier;
88  protocolLayerOptions.LeaseId = options.AccessConditions.LeaseId;
89  protocolLayerOptions.IfModifiedSince = options.AccessConditions.IfModifiedSince;
90  protocolLayerOptions.IfUnmodifiedSince = options.AccessConditions.IfUnmodifiedSince;
91  protocolLayerOptions.IfMatch = options.AccessConditions.IfMatch;
92  protocolLayerOptions.IfNoneMatch = options.AccessConditions.IfNoneMatch;
93  protocolLayerOptions.IfTags = options.AccessConditions.TagConditions;
94  if (m_customerProvidedKey.HasValue())
95  {
96  protocolLayerOptions.EncryptionKey = m_customerProvidedKey.GetValue().Key;
97  protocolLayerOptions.EncryptionKeySha256 = m_customerProvidedKey.GetValue().KeyHash;
98  protocolLayerOptions.EncryptionAlgorithm = m_customerProvidedKey.GetValue().Algorithm;
99  }
100  protocolLayerOptions.EncryptionScope = m_encryptionScope;
101  return BlobRestClient::BlockBlob::Upload(
102  options.Context, *m_pipeline, m_blobUrl, content, protocolLayerOptions);
103  }

◆ UploadFrom() [1/2]

Azure::Core::Response< UploadBlockBlobFromResult > Azure::Storage::Blobs::BlockBlobClient::UploadFrom ( const std::string &  file,
const UploadBlockBlobFromOptions options = UploadBlockBlobFromOptions() 
) const

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.

Parameters
fileA file containing the content to upload.
optionsOptional parameters to execute this function.
Returns
A UploadBlockBlobFromResult describing the state of the updated block blob.
186  {
187  constexpr int64_t c_defaultBlockSize = 8 * 1024 * 1024;
188  constexpr int64_t c_maximumNumberBlocks = 50000;
189  constexpr int64_t c_grainSize = 4 * 1024;
190 
191  Details::FileReader fileReader(file);
192 
193  int64_t chunkSize = c_defaultBlockSize;
194  if (options.ChunkSize.HasValue())
195  {
196  chunkSize = options.ChunkSize.GetValue();
197  }
198  else
199  {
200  int64_t minBlockSize
201  = (fileReader.GetFileSize() + c_maximumNumberBlocks - 1) / c_maximumNumberBlocks;
202  chunkSize = std::max(chunkSize, minBlockSize);
203  chunkSize = (chunkSize + c_grainSize - 1) / c_grainSize * c_grainSize;
204  }
205 
206  if (fileReader.GetFileSize() <= chunkSize)
207  {
208  Azure::Core::Http::FileBodyStream contentStream(
209  fileReader.GetHandle(), 0, fileReader.GetFileSize());
210  UploadBlockBlobOptions uploadBlockBlobOptions;
211  uploadBlockBlobOptions.Context = options.Context;
212  uploadBlockBlobOptions.HttpHeaders = options.HttpHeaders;
213  uploadBlockBlobOptions.Metadata = options.Metadata;
214  uploadBlockBlobOptions.Tier = options.Tier;
215  return Upload(&contentStream, uploadBlockBlobOptions);
216  }
217 
218  std::vector<std::pair<BlockType, std::string>> blockIds;
219  auto getBlockId = [](int64_t id) {
220  constexpr std::size_t c_blockIdLength = 64;
221  std::string blockId = std::to_string(id);
222  blockId = std::string(c_blockIdLength - blockId.length(), '0') + blockId;
223  return Base64Encode(blockId);
224  };
225 
226  auto uploadBlockFunc = [&](int64_t offset, int64_t length, int64_t chunkId, int64_t numChunks) {
227  Azure::Core::Http::FileBodyStream contentStream(fileReader.GetHandle(), offset, length);
228  StageBlockOptions chunkOptions;
229  chunkOptions.Context = options.Context;
230  auto blockInfo = StageBlock(getBlockId(chunkId), &contentStream, chunkOptions);
231  if (chunkId == numChunks - 1)
232  {
233  blockIds.resize(static_cast<std::size_t>(numChunks));
234  }
235  };
236 
237  Details::ConcurrentTransfer(
238  0, fileReader.GetFileSize(), chunkSize, options.Concurrency, uploadBlockFunc);
239 
240  for (std::size_t i = 0; i < blockIds.size(); ++i)
241  {
242  blockIds[i].first = BlockType::Uncommitted;
243  blockIds[i].second = getBlockId(static_cast<int64_t>(i));
244  }
245  CommitBlockListOptions commitBlockListOptions;
246  commitBlockListOptions.Context = options.Context;
247  commitBlockListOptions.HttpHeaders = options.HttpHeaders;
248  commitBlockListOptions.Metadata = options.Metadata;
249  commitBlockListOptions.Tier = options.Tier;
250  auto commitBlockListResponse = CommitBlockList(blockIds, commitBlockListOptions);
251 
252  UploadBlockBlobFromResult result;
253  result.ETag = commitBlockListResponse->ETag;
254  result.LastModified = commitBlockListResponse->LastModified;
255  result.VersionId = commitBlockListResponse->VersionId;
256  result.ServerEncrypted = commitBlockListResponse->ServerEncrypted;
257  result.EncryptionKeySha256 = commitBlockListResponse->EncryptionKeySha256;
258  result.EncryptionScope = commitBlockListResponse->EncryptionScope;
259  return Azure::Core::Response<UploadBlockBlobFromResult>(
260  std::move(result),
261  std::make_unique<Azure::Core::Http::RawResponse>(
262  std::move(commitBlockListResponse.GetRawResponse())));
263  }

◆ UploadFrom() [2/2]

Azure::Core::Response< UploadBlockBlobFromResult > Azure::Storage::Blobs::BlockBlobClient::UploadFrom ( const uint8_t *  buffer,
std::size_t  bufferSize,
const UploadBlockBlobFromOptions options = UploadBlockBlobFromOptions() 
) const

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.

Parameters
bufferA memory buffer containing the content to upload.
bufferSizeSize of the memory buffer.
optionsOptional parameters to execute this function.
Returns
A UploadBlockBlobFromResult describing the state of the updated block blob.
109  {
110  constexpr int64_t c_defaultBlockSize = 8 * 1024 * 1024;
111  constexpr int64_t c_maximumNumberBlocks = 50000;
112  constexpr int64_t c_grainSize = 4 * 1024;
113 
114  int64_t chunkSize = c_defaultBlockSize;
115  if (options.ChunkSize.HasValue())
116  {
117  chunkSize = options.ChunkSize.GetValue();
118  }
119  else
120  {
121  int64_t minBlockSize = (bufferSize + c_maximumNumberBlocks - 1) / c_maximumNumberBlocks;
122  chunkSize = std::max(chunkSize, minBlockSize);
123  chunkSize = (chunkSize + c_grainSize - 1) / c_grainSize * c_grainSize;
124  }
125 
126  if (bufferSize <= static_cast<std::size_t>(chunkSize))
127  {
128  Azure::Core::Http::MemoryBodyStream contentStream(buffer, bufferSize);
129  UploadBlockBlobOptions uploadBlockBlobOptions;
130  uploadBlockBlobOptions.Context = options.Context;
131  uploadBlockBlobOptions.HttpHeaders = options.HttpHeaders;
132  uploadBlockBlobOptions.Metadata = options.Metadata;
133  uploadBlockBlobOptions.Tier = options.Tier;
134  return Upload(&contentStream, uploadBlockBlobOptions);
135  }
136 
137  std::vector<std::pair<BlockType, std::string>> blockIds;
138  auto getBlockId = [](int64_t id) {
139  constexpr std::size_t c_blockIdLength = 64;
140  std::string blockId = std::to_string(id);
141  blockId = std::string(c_blockIdLength - blockId.length(), '0') + blockId;
142  return Base64Encode(blockId);
143  };
144 
145  auto uploadBlockFunc = [&](int64_t offset, int64_t length, int64_t chunkId, int64_t numChunks) {
146  Azure::Core::Http::MemoryBodyStream contentStream(buffer + offset, length);
147  StageBlockOptions chunkOptions;
148  chunkOptions.Context = options.Context;
149  auto blockInfo = StageBlock(getBlockId(chunkId), &contentStream, chunkOptions);
150  if (chunkId == numChunks - 1)
151  {
152  blockIds.resize(static_cast<std::size_t>(numChunks));
153  }
154  };
155 
156  Details::ConcurrentTransfer(0, bufferSize, chunkSize, options.Concurrency, uploadBlockFunc);
157 
158  for (std::size_t i = 0; i < blockIds.size(); ++i)
159  {
160  blockIds[i].first = BlockType::Uncommitted;
161  blockIds[i].second = getBlockId(static_cast<int64_t>(i));
162  }
163  CommitBlockListOptions commitBlockListOptions;
164  commitBlockListOptions.Context = options.Context;
165  commitBlockListOptions.HttpHeaders = options.HttpHeaders;
166  commitBlockListOptions.Metadata = options.Metadata;
167  commitBlockListOptions.Tier = options.Tier;
168  auto commitBlockListResponse = CommitBlockList(blockIds, commitBlockListOptions);
169 
170  UploadBlockBlobFromResult ret;
171  ret.ETag = std::move(commitBlockListResponse->ETag);
172  ret.LastModified = std::move(commitBlockListResponse->LastModified);
173  ret.VersionId = std::move(commitBlockListResponse->VersionId);
174  ret.ServerEncrypted = commitBlockListResponse->ServerEncrypted;
175  ret.EncryptionKeySha256 = std::move(commitBlockListResponse->EncryptionKeySha256);
176  ret.EncryptionScope = std::move(commitBlockListResponse->EncryptionScope);
177  return Azure::Core::Response<UploadBlockBlobFromResult>(
178  std::move(ret),
179  std::make_unique<Azure::Core::Http::RawResponse>(
180  std::move(commitBlockListResponse.GetRawResponse())));
181  }

◆ WithSnapshot()

BlockBlobClient Azure::Storage::Blobs::BlockBlobClient::WithSnapshot ( const std::string &  snapshot) const

Initializes a new instance of the BlockBlobClient class with an identical uri source but the specified snapshot timestamp.

Parameters
snapshotThe snapshot identifier.
Returns
A new BlockBlobClient instance.
Remarks
Pass empty string to remove the snapshot returning the base blob.
51  {
52  BlockBlobClient newClient(*this);
53  if (snapshot.empty())
54  {
55  newClient.m_blobUrl.RemoveQuery(Details::c_HttpQuerySnapshot);
56  }
57  else
58  {
59  newClient.m_blobUrl.AppendQuery(Details::c_HttpQuerySnapshot, snapshot);
60  }
61  return newClient;
62  }

◆ WithVersionId()

BlockBlobClient Azure::Storage::Blobs::BlockBlobClient::WithVersionId ( const std::string &  versionId) const

Creates a clone of this instance that references a version ID rather than the base blob.

Parameters
versionIdThe version ID returning a URL to the base blob.
Returns
A new BlockBlobClient instance.
Remarks
Pass empty string to remove the version ID returning the base blob.
65  {
66  BlockBlobClient newClient(*this);
67  if (versionId.empty())
68  {
69  newClient.m_blobUrl.RemoveQuery(Details::c_HttpQueryVersionId);
70  }
71  else
72  {
73  newClient.m_blobUrl.AppendQuery(Details::c_HttpQueryVersionId, versionId);
74  }
75  return newClient;
76  }

The documentation for this class was generated from the following files:
Azure::Storage::Blobs::BlobClient::CreateFromConnectionString
static BlobClient CreateFromConnectionString(const std::string &connectionString, const std::string &containerName, const std::string &blobName, const BlobClientOptions &options=BlobClientOptions())
Initialize a new instance of BlobClient.
Definition: blob_client.cpp:22
Azure::Storage::Blobs::BlockBlobClient::Upload
Azure::Core::Response< UploadBlockBlobResult > Upload(Azure::Core::Http::BodyStream *content, const UploadBlockBlobOptions &options=UploadBlockBlobOptions()) const
Creates a new block blob, or updates the content of an existing block blob. Updating an existing bloc...
Definition: block_blob_client.cpp:78
Azure::Storage::Blobs::BlockBlobClient::StageBlock
Azure::Core::Response< StageBlockResult > StageBlock(const std::string &blockId, Azure::Core::Http::BodyStream *content, const StageBlockOptions &options=StageBlockOptions()) const
Creates a new block as part of a block blob's staging area to be eventually committed via the CommitB...
Definition: block_blob_client.cpp:265
Azure::Storage::Blobs::BlockBlobClient::BlockBlobClient
BlockBlobClient(const std::string &blobUri, std::shared_ptr< SharedKeyCredential > credential, const BlockBlobClientOptions &options=BlockBlobClientOptions())
Initialize a new instance of BlockBlobClient.
Definition: block_blob_client.cpp:25
Azure::Storage::Blobs::BlockBlobClient::CommitBlockList
Azure::Core::Response< CommitBlockListResult > CommitBlockList(const std::vector< std::pair< BlockType, std::string >> &blockIds, const CommitBlockListOptions &options=CommitBlockListOptions()) const
Writes a blob by specifying the list of block IDs that make up the blob. In order to be written as pa...
Definition: block_blob_client.cpp:325