azure-storage-blobs
blob_client.hpp
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // SPDX-License-Identifier: MIT
3 
4 #pragma once
5 
6 #include "azure/core/credentials/credentials.hpp"
7 #include "azure/storage/blobs/blob_options.hpp"
8 #include "azure/storage/blobs/blob_responses.hpp"
9 #include "azure/storage/blobs/protocol/blob_rest_client.hpp"
10 #include "azure/storage/common/storage_credential.hpp"
11 
12 #include <map>
13 #include <memory>
14 #include <string>
15 
16 namespace Azure { namespace Storage { namespace Files { namespace DataLake {
17  class DirectoryClient;
18  class FileClient;
19 }}}} // namespace Azure::Storage::Files::DataLake
20 
21 namespace Azure { namespace Storage { namespace Blobs {
22 
23  class BlockBlobClient;
24  class AppendBlobClient;
25  class PageBlobClient;
26 
30  class BlobClient {
31  public:
44  const std::string& connectionString,
45  const std::string& containerName,
46  const std::string& blobName,
47  const BlobClientOptions& options = BlobClientOptions());
48 
58  explicit BlobClient(
59  const std::string& blobUri,
60  std::shared_ptr<SharedKeyCredential> credential,
61  const BlobClientOptions& options = BlobClientOptions());
62 
72  explicit BlobClient(
73  const std::string& blobUri,
74  std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
75  const BlobClientOptions& options = BlobClientOptions());
76 
86  explicit BlobClient(
87  const std::string& blobUri,
88  const BlobClientOptions& options = BlobClientOptions());
89 
98 
106 
114 
120  std::string GetUri() const { return m_blobUrl.GetAbsoluteUrl(); }
121 
130  BlobClient WithSnapshot(const std::string& snapshot) const;
131 
140  BlobClient WithVersionId(const std::string& versionId) const;
141 
149  Azure::Core::Response<GetBlobPropertiesResult> GetProperties(
150  const GetBlobPropertiesOptions& options = GetBlobPropertiesOptions()) const;
151 
159  Azure::Core::Response<SetBlobHttpHeadersResult> SetHttpHeaders(
160  BlobHttpHeaders httpHeaders,
161  const SetBlobHttpHeadersOptions& options = SetBlobHttpHeadersOptions()) const;
162 
172  Azure::Core::Response<SetBlobMetadataResult> SetMetadata(
173  std::map<std::string, std::string> metadata,
174  const SetBlobMetadataOptions& options = SetBlobMetadataOptions()) const;
175 
185  Azure::Core::Response<SetBlobAccessTierResult> SetAccessTier(
186  AccessTier Tier,
187  const SetBlobAccessTierOptions& options = SetBlobAccessTierOptions()) const;
188 
201  Azure::Core::Response<StartCopyBlobFromUriResult> StartCopyFromUri(
202  const std::string& sourceUri,
204 
213  Azure::Core::Response<AbortCopyBlobFromUriResult> AbortCopyFromUri(
214  const std::string& copyId,
216 
225  Azure::Core::Response<DownloadBlobResult> Download(
226  const DownloadBlobOptions& options = DownloadBlobOptions()) const;
227 
238  Azure::Core::Response<DownloadBlobToResult> DownloadTo(
239  uint8_t* buffer,
240  std::size_t bufferSize,
241  const DownloadBlobToOptions& options = DownloadBlobToOptions()) const;
242 
251  Azure::Core::Response<DownloadBlobToResult> DownloadTo(
252  const std::string& file,
253  const DownloadBlobToOptions& options = DownloadBlobToOptions()) const;
254 
261  Azure::Core::Response<CreateBlobSnapshotResult> CreateSnapshot(
262  const CreateBlobSnapshotOptions& options = CreateBlobSnapshotOptions()) const;
263 
272  Azure::Core::Response<DeleteBlobResult> Delete(
273  const DeleteBlobOptions& options = DeleteBlobOptions()) const;
274 
282  Azure::Core::Response<UndeleteBlobResult> Undelete(
283  const UndeleteBlobOptions& options = UndeleteBlobOptions()) const;
284 
296  Azure::Core::Response<AcquireBlobLeaseResult> AcquireLease(
297  const std::string& proposedLeaseId,
298  int32_t duration,
299  const AcquireBlobLeaseOptions& options = AcquireBlobLeaseOptions()) const;
300 
308  Azure::Core::Response<RenewBlobLeaseResult> RenewLease(
309  const std::string& leaseId,
310  const RenewBlobLeaseOptions& options = RenewBlobLeaseOptions()) const;
311 
319  Azure::Core::Response<ReleaseBlobLeaseResult> ReleaseLease(
320  const std::string& leaseId,
321  const ReleaseBlobLeaseOptions& options = ReleaseBlobLeaseOptions()) const;
322 
332  Azure::Core::Response<ChangeBlobLeaseResult> ChangeLease(
333  const std::string& leaseId,
334  const std::string& proposedLeaseId,
335  const ChangeBlobLeaseOptions& options = ChangeBlobLeaseOptions()) const;
336 
343  Azure::Core::Response<BreakBlobLeaseResult> BreakLease(
344  const BreakBlobLeaseOptions& options = BreakBlobLeaseOptions()) const;
345 
353  Azure::Core::Response<SetBlobTagsResult> SetTags(
354  std::map<std::string, std::string> tags,
355  const SetBlobTagsOptions& options = SetBlobTagsOptions()) const;
356 
363  Azure::Core::Response<GetBlobTagsResult> GetTags(
364  const GetBlobTagsOptions& options = GetBlobTagsOptions()) const;
365 
366  protected:
367  Azure::Core::Http::Url m_blobUrl;
368  std::shared_ptr<Azure::Core::Http::HttpPipeline> m_pipeline;
369  Azure::Core::Nullable<EncryptionKey> m_customerProvidedKey;
370  Azure::Core::Nullable<std::string> m_encryptionScope;
371 
372  private:
373  explicit BlobClient(
374  Azure::Core::Http::Url blobUri,
375  std::shared_ptr<Azure::Core::Http::HttpPipeline> pipeline,
376  Azure::Core::Nullable<EncryptionKey> customerProvidedKey,
377  Azure::Core::Nullable<std::string> encryptionScope)
378  : m_blobUrl(std::move(blobUri)), m_pipeline(std::move(pipeline)),
379  m_customerProvidedKey(std::move(customerProvidedKey)),
380  m_encryptionScope(std::move(encryptionScope))
381  {
382  }
383 
384  friend class BlobContainerClient;
385  friend class Files::DataLake::DirectoryClient;
386  friend class Files::DataLake::FileClient;
387  };
388 }}} // namespace Azure::Storage::Blobs
Azure::Storage::Blobs::BlobClient::CreateSnapshot
Azure::Core::Response< CreateBlobSnapshotResult > CreateSnapshot(const CreateBlobSnapshotOptions &options=CreateBlobSnapshotOptions()) const
Creates a read-only snapshot of a blob.
Definition: blob_client.cpp:586
Azure::Storage::Blobs::BlobClient::Undelete
Azure::Core::Response< UndeleteBlobResult > Undelete(const UndeleteBlobOptions &options=UndeleteBlobOptions()) const
Restores the contents and metadata of a soft deleted blob and any associated soft deleted snapshots.
Definition: blob_client.cpp:622
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::BlobClient::Download
Azure::Core::Response< DownloadBlobResult > Download(const DownloadBlobOptions &options=DownloadBlobOptions()) const
Downloads a blob or a blob range from the service, including its metadata and properties.
Definition: blob_client.cpp:157
Azure::Storage::Blobs::DownloadBlobOptions
Optional parameters for BlobClient::Download.
Definition: blob_options.hpp:691
Azure::Storage::Blobs::BlobClient::WithVersionId
BlobClient WithVersionId(const std::string &versionId) const
Creates a clone of this instance that references a version ID rather than the base blob.
Definition: blob_client.cpp:143
Azure::Storage::Blobs::BlobClient
The BlobClient allows you to manipulate Azure Storage blobs.
Definition: blob_client.hpp:30
Azure::Storage::Blobs::AcquireBlobLeaseOptions
Optional parameters for BlobClient::AcquireLease.
Definition: blob_options.hpp:817
Azure::Storage::Blobs::BlobHttpHeaders
Definition: blob_rest_client.hpp:380
Azure::Storage::Blobs::SetBlobHttpHeadersOptions
Optional parameters for BlobClient::SetHttpHeaders.
Definition: blob_options.hpp:578
Azure::Storage::Blobs::BlobClient::AbortCopyFromUri
Azure::Core::Response< AbortCopyBlobFromUriResult > AbortCopyFromUri(const std::string &copyId, const AbortCopyBlobFromUriOptions &options=AbortCopyBlobFromUriOptions()) const
Aborts a pending StartCopyFromUri operation, and leaves this blob with zero length and full metadata.
Definition: blob_client.cpp:575
Azure::Storage::Blobs::BlobClient::GetPageBlobClient
PageBlobClient GetPageBlobClient() const
Creates a new PageBlobClient object with the same uri as this BlobClient. The new PageBlobClient uses...
Definition: blob_client.cpp:127
Azure::Storage::Blobs::BlobClient::StartCopyFromUri
Azure::Core::Response< StartCopyBlobFromUriResult > StartCopyFromUri(const std::string &sourceUri, const StartCopyBlobFromUriOptions &options=StartCopyBlobFromUriOptions()) const
Copies data at from the source to this blob.
Definition: blob_client.cpp:549
Azure::Storage::Blobs::BreakBlobLeaseOptions
Optional parameters for BlobClient::BreakLease.
Definition: blob_options.hpp:869
Azure::Storage::Blobs::ChangeBlobLeaseOptions
Optional parameters for BlobClient::ChangeLease.
Definition: blob_options.hpp:843
Azure::Storage::Blobs::StartCopyBlobFromUriOptions
Optional parameters for BlobClient::StartCopyFromUri.
Definition: blob_options.hpp:628
Azure::Storage::Blobs::PageBlobClient
Definition: page_blob_client.hpp:26
Azure::Storage::Blobs::BlobClient::GetProperties
Azure::Core::Response< GetBlobPropertiesResult > GetProperties(const GetBlobPropertiesOptions &options=GetBlobPropertiesOptions()) const
Returns all user-defined metadata, standard HTTP properties, and system properties for the blob....
Definition: blob_client.cpp:479
Azure::Storage::Blobs::BlobClientOptions
Blob client options used to initalize BlobClient.
Definition: blob_options.hpp:513
Azure::Storage::Blobs::BlobClient::SetAccessTier
Azure::Core::Response< SetBlobAccessTierResult > SetAccessTier(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 ...
Definition: blob_client.cpp:538
Azure::Storage::Blobs::BlobClient::BlobClient
BlobClient(const std::string &blobUri, std::shared_ptr< SharedKeyCredential > credential, const BlobClientOptions &options=BlobClientOptions())
Initialize a new instance of BlobClient.
Definition: blob_client.cpp:43
Azure::Storage::Blobs::SetBlobMetadataOptions
Optional parameters for BlobClient::SetMetadata.
Definition: blob_options.hpp:594
Azure::Storage::Blobs::BlobClient::GetBlockBlobClient
BlockBlobClient GetBlockBlobClient() const
Creates a new BlockBlobClient object with the same uri as this BlobClient. The new BlockBlobClient us...
Definition: blob_client.cpp:123
Azure::Storage::Blobs::SetBlobTagsOptions
Optional parameters for BlobClient::SetTags.
Definition: blob_options.hpp:889
Azure::Storage::Blobs::BlobClient::SetTags
Azure::Core::Response< SetBlobTagsResult > SetTags(std::map< std::string, std::string > tags, const SetBlobTagsOptions &options=SetBlobTagsOptions()) const
Sets tags on the underlying blob.
Definition: blob_client.cpp:708
Azure::Storage::Blobs::BlobClient::RenewLease
Azure::Core::Response< RenewBlobLeaseResult > RenewLease(const std::string &leaseId, const RenewBlobLeaseOptions &options=RenewBlobLeaseOptions()) const
Renews the blob's previously-acquired lease.
Definition: blob_client.cpp:647
Azure::Storage::Blobs::BlobClient::ChangeLease
Azure::Core::Response< ChangeBlobLeaseResult > ChangeLease(const std::string &leaseId, const std::string &proposedLeaseId, const ChangeBlobLeaseOptions &options=ChangeBlobLeaseOptions()) const
Changes the lease of an active lease.
Definition: blob_client.cpp:677
Azure::Storage::Blobs::RenewBlobLeaseOptions
Optional parameters for BlobClient::RenewLease.
Definition: blob_options.hpp:830
Azure::Storage::Blobs::DeleteBlobOptions
Optional parameters for BlobClient::Delete.
Definition: blob_options.hpp:781
Azure::Storage::Blobs::BlobClient::DownloadTo
Azure::Core::Response< DownloadBlobToResult > DownloadTo(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.
Definition: blob_client.cpp:221
Azure::Storage::Blobs::BlobClient::ReleaseLease
Azure::Core::Response< ReleaseBlobLeaseResult > ReleaseLease(const std::string &leaseId, const ReleaseBlobLeaseOptions &options=ReleaseBlobLeaseOptions()) const
Releases the blob's previously-acquired lease.
Definition: blob_client.cpp:662
Azure::Storage::Blobs::BlobClient::GetAppendBlobClient
AppendBlobClient GetAppendBlobClient() const
Creates a new AppendBlobClient object with the same uri as this BlobClient. The new AppendBlobClient ...
Definition: blob_client.cpp:125
Azure::Storage::Blobs::CreateBlobSnapshotOptions
Optional parameters for BlobClient::CreateSnapshot.
Definition: blob_options.hpp:757
Azure::Storage::Blobs::BlobClient::GetTags
Azure::Core::Response< GetBlobTagsResult > GetTags(const GetBlobTagsOptions &options=GetBlobTagsOptions()) const
Gets the tags associated with the underlying blob.
Definition: blob_client.cpp:719
Azure::Storage::Blobs::BlockBlobClient
The BlockBlobClient allows you to manipulate Azure Storage block blobs.
Definition: block_blob_client.hpp:34
Azure::Storage::Blobs::BlobClient::BreakLease
Azure::Core::Response< BreakBlobLeaseResult > BreakLease(const BreakBlobLeaseOptions &options=BreakBlobLeaseOptions()) const
Breaks the previously-acquired lease.
Definition: blob_client.cpp:694
Azure::Storage::Blobs::BlobClient::AcquireLease
Azure::Core::Response< AcquireBlobLeaseResult > AcquireLease(const std::string &proposedLeaseId, int32_t duration, const AcquireBlobLeaseOptions &options=AcquireBlobLeaseOptions()) const
Acquires a lease on the blob.
Definition: blob_client.cpp:630
Azure::Storage::Blobs::AppendBlobClient
The AppendBlobClient allows you to manipulate Azure Storage append blobs.
Definition: append_blob_client.hpp:24
Azure::Storage::Blobs::DownloadBlobToOptions
Optional parameters for BlobClient::DownloadTo.
Definition: blob_options.hpp:718
Azure::Storage::Blobs::ReleaseBlobLeaseOptions
Optional parameters for BlobClient::ReleaseLease.
Definition: blob_options.hpp:856
Azure::Storage::Blobs::GetBlobTagsOptions
Optional parameters for BlobClient::GetTags.
Definition: blob_options.hpp:900
Azure::Storage::Blobs::GetBlobPropertiesOptions
Optional parameters for BlobClient::GetProperties.
Definition: blob_options.hpp:562
Azure::Storage::Blobs::BlobClient::SetHttpHeaders
Azure::Core::Response< SetBlobHttpHeadersResult > SetHttpHeaders(BlobHttpHeaders httpHeaders, const SetBlobHttpHeadersOptions &options=SetBlobHttpHeadersOptions()) const
Sets system properties on the blob.
Definition: blob_client.cpp:499
Azure::Storage::Blobs::BlobClient::Delete
Azure::Core::Response< DeleteBlobResult > Delete(const DeleteBlobOptions &options=DeleteBlobOptions()) const
Marks the specified blob or snapshot for deletion. The blob is later deleted during garbage collectio...
Definition: blob_client.cpp:608
Azure::Storage::Blobs::BlobClient::WithSnapshot
BlobClient WithSnapshot(const std::string &snapshot) const
Initializes a new instance of the BlobClient class with an identical uri source but the specified sna...
Definition: blob_client.cpp:129
Azure::Storage::Blobs::UndeleteBlobOptions
Optional parameters for BlobClient::Undelete.
Definition: blob_options.hpp:804
Azure::Storage::Blobs::BlobClient::SetMetadata
Azure::Core::Response< SetBlobMetadataResult > SetMetadata(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.
Definition: blob_client.cpp:515
Azure::Storage::Blobs::AbortCopyBlobFromUriOptions
Optional parameters for BlobClient::AbortCopyFromUri.
Definition: blob_options.hpp:675
Azure::Storage::Blobs::BlobClient::GetUri
std::string GetUri() const
Gets the blob's primary uri endpoint.
Definition: blob_client.hpp:120
Azure::Storage::Blobs::SetBlobAccessTierOptions
Optional parameters for BlobClient::SetAccessTier.
Definition: blob_options.hpp:610