Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
62 views
11 pages
Azure Blob Storage Client Library For C++
Uploaded by
Sanskar
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save Azure Blob Storage client library for C++ For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
62 views
11 pages
Azure Blob Storage Client Library For C++
Uploaded by
Sanskar
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save Azure Blob Storage client library for C++ For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save Azure Blob Storage client library for C++ For Later
You are on page 1
/ 11
Search
Fullscreen
‘2124, 5:14 PM (Quickstart: Azur Blob Storage brary - C++ - Azure Storage | Microsoft Learn Quickstart: Azure Blob Storage client library for C++ Article + 08/31/2023 Get started with the Azure Blob Storage client library for C++. Azure Blob Storage is Microsoft's object storage solution for the cloud. Follow these steps to install the package and try out example code for basic tasks. | API reference documentation | Library source code__| Samples | Prerequisites ‘* Azure subscription - create one for free ‘* Azure storage account - create a storage account * C++ compiler © CMake * vepkg - Cand C++ package manager Setting up This section walks you through preparing a project to work with the Azure Blob Storage client library for C++, The easiest way to acquire the Azure SDK for C++ is to use the vepkg package manager. @ Install the packages Use the vepkg install command to install the Azure Blob Storage library for C++ and necessary dependencies: console vepkg.exe install azure-storage-blobs-cpp The Azure Identity library is needed for passwordless connections to Azure services: console nitps:leam mierosot.comlon-usfazuelstorage/oobsiquicksta-blobs-cplus-plus tabs=managed-dentiy'%2Croles-a2ure-portal ant‘22124, 5:14 PM (Quickstart: Azure Blob Storage brary - C++ - Azure Storage | Microsoft Learn vepkg.exe install azure-identity-cpp For more information on project setup and working with the Azure SDK for C++, see the Azure SDK for C++ readme Create the project In Visual Studio, create a new C++ console application for Windows called BlobQuickstart. =a x Configure your new project Console App ++ = Windows Console ieee cee 1] i Ba | [oa Object model Azure Blob Storage is optimized for storing massive amounts of unstructured data Unstructured data is data that doesn’t adhere to a particular data model or definition, such as text or binary data. Blob Storage offers three types of resources: © The storage account * Acontainer in the storage account * Ablob in the container nitps:leam mierosot.comlon-usfazuelstorage/oobsiquicksta-blobs-cplus-plus tabs=managed-dentiy'%2Croles-a2ure-portal aint‘2124, 5:14 PM (Quickstart: Azur Blob Storage brary - C++ - Azure Storage | Microsoft Learn The following diagram shows the relationship between these resources. EM pictues 7 Ea] imgeotsps TT Ba img002jpq MM movies, Im movi.avi Use these C++ classes to interact with these resources: © BlobServiceClient : The BlobserviceClient class allows you to manipulate Azure Storage resources and blob containers. * BlobContainerClient : The BlobContainerClient class allows you to manipulate Azure Storage containers and their blobs * BlobClient : The Blobclient class allows you to manipulate Azure Storage blobs. It's the base class for all specialized blob classes. * BlockBlobClient : The BlockBlobClient class allows you to manipulate Azure Storage block blobs. Code examples These example code snippets show you how to do the following tasks with the Azure Blob Storage client library for C++ * Add include files © Authenticate to Azure and authorize access to blob data Create a container ‘* Upload blobs to a container * List the blobs in a container * Download blobs © Delete a container Add include files From the project directory: 1. Open the BlobQuickstart.sin solution file in Visual Studio 2. Inside Visual Studio, open the BlobQuickstart.epp source file 3, Remove any code inside main that was autogenerated nitps:leam mierosot.comlon-usfazuelstorage/oobsiquicksta-blobs-cplus-plus tabs=managed-dentiy'%2Croles-a2ure-portal ait‘2124, 5:14 PM (Quickstart: Azur Blob Storage brary - C++ - Azure Storage | Microsoft Learn 4, Add #include and using namespace statements ce #include
#include
tinclude
include
using namespace Azure using namespace Azure Authenticate to Azure and authorize access to blob data Application requests to Azure Blob Storage must be authorized. Using the Defaultazurecredential class provided by the Azure Identity client library is the recommended approach for implementing passwordless connections to Azure services in your code, including Blob Storage. You can also authorize requests to Azure Blob Storage by using the account access key. However, this approach should be used with caution, Developers must be diligent to never expose the access key in an unsecure location. Anyone who has the access key is able to authorize requests against the storage account, and effectively has access to all the data. DefaultAzurecredential offers improved management and security benefits over the account key to allow passwordless authentication. Both options are demonstrated in the following example. Passwordless (Recommended) The Azure Identity library provides Microsoft Entra token authentication support across the Azure SDK. It provides a set of Tokencredential implementations which can be used to construct Azure SDK clients which support Microsoft Entra token authentication. befaultazureCredential supports multiple authentication methods and determines which method should be used at runtime. Assign roles to your Microsoft Entra user account When developing locally, make sure that the user account that is accessing blob data has the correct permissions. You'll need Storage Blob Data Contributor to read and ntps:leam mierosot.comlon-usfazuelstorage/olobsiquicksta-blobs-cplus-plus tabs=managed-identiy'42Croles-a2ure-portal ant‘1204, 5:14 Pm Quickstart Azure lob Storage forary C++ Azure Storage | Microsoft Lean write blob data. To assign yourself this role, you'll need to be assigned the User Access Administrator role, or another role that includes the Microsoft.Authorization/roleAssignments/write action. You can assign Azure RBAC roles to a user using the Azure portal, Azure CLI, or Azure PowerShell. You can learn more about the available scopes for role assignments on the scope overview page. In this scenario, you'll assign permissions to your user account, scoped to the storage account, to follow the Principle of Least Privilege. This practice gives users only the minimum permissions needed and creates more secure production environments. The following example will assign the Storage Blob Data Contributor role to your user account, which provides both read and write access to blob data in your storage account. © Important In most cases it will take a minute or two for the role assignment to propagate in ‘Azure, but in rare cases it may take up to eight minutes. If you receive authentication errors when you first run your code, wait a few moments and try again. ‘Azure portal 1. In the Azure portal, locate your storage account using the main search bar or left navigation 2. On the storage account overview page, select Access control (IAM) from the left-hand menu 3. On the Access control (IAM) page, select the Role assignments tab. 4. Select + Add from the top menu and then Add role assignment from the resulting drop-down menu. ntps:leam mierosot.comlon-usfazuelstorage/olobsiquickstar-blobs-cplus-plus tabs=managed-identiy'%2Croles-a2ure-portal sit‘yozi2a, 5:14 PM (Quickstart: Azure Blob Storage brary - C++ - Azure Storage | Microsoft Learn ig identitymigrationstorage | Access Control (VAM) 5. Use the search box to filter the results to the desired role. For this example, search for Storage Blob Data Contributor and select the matching result and then choose Next. 6. Under Assign access to, select User, group, or service principal, and then choose + Select members. 7. In the dialog, search for your Microsoft Entra username (usually your user@domain email address) and then choose Select at the bottom of the dialog 8, Select Review + assign to go to the final page, and then Review + assign again to complete the process. Sign in and connect your app code to Azure using DefaultAzureCredential You can authorize access to data in your storage account using the following steps: 1, Make sure you're authenticated with the same Microsoft Entra account you assigned the role to on your storage account. You can authenticate via Azure CLI. Sign in to Azure through the Azure CLI using the following command: ‘Azure CU az login /ntps:leam microsof. comier-usiazure/storagelblobs/quckstatblobs-cplus-plusiabs=managed-dentiy%2Croles-szure-portal ent‘22124, 514 PM Quickstart: Azure Blob Storage library - C++ - Azure Storage | Microsoft Lear 2. To use Defaultazurecredential, make sure that the azure-identity-cpp package is installed and the following #include is added: coe #include
3. Add this code to the end of main() . When the code runs on your local workstation, DefaultAzureCredential uses the developer credentials for Azure CLI to authenticate to Azure. cee // Initialize an instance of DefaultAzureCredential auto defaultAzureCredential - std: imake_shared
(); auto accountURL = "https://
. blob. core. windows .ne' BlobServiceClient blobServiceClient(accounturL, defaultAzureCredential) ; 4, Make sure to update the storage account name in the URI of your BlobServiceClient object. The storage account name can be found on the overview page of the Azure portal Ho «s [identitymigrationstorage] » Pare | F upload Hy openinerpoee Gl pete > weve YO) retesh = cvensiew = Asante w ecouce grup aus) + sence rnp Location cast Primary/Saconday Primary: as US, Seconda: West US sohe problems 2 Subserpton (asus) + CBL Coss ence Coren Team Testing i subserpbon 0 © caeameton Dakaste Primary Arable Second: vale ont eas ei Jenere to add tags BS Sorge brouser © Note ntps:leam microsof. comier-usiazure/storagelblobs/quckstatblobs-cplus-plusiabs=managed-dentiy%2Croles-szure-portal mm‘yo24, 5:14 Pm Quickstart: Azure Blob Storage ibrary «Cr+ - Azure Storage | Microsoft Lear When using the C++ SDK in a production environment, it's recommended that you only enable credentials that you know your application will use Instead of using efaultazureCredential, you should authorize using a specific credential type, or by using ChainedTokenCredential with the supported credentials. Create a container Decide on a name for the new container. Then create an instance of BlobContainerClient and create the container. © Important Container names must be lowercase. For more information about naming containers and blobs, see Naming and Referencing Containers, Blobs, and Metadata. Add this code to the end of main(): ce std::string containerName = "myblobcontainer"; auto containerClient = blobServiceClient .GetBlobContainerClient(""nyblobcon- tainer"); // Create the container if it does not exist std::cout << “Creating container: " << containerName << std::endl; containerClient.CreateIfNotexists(); Upload blobs to a container The following code snippet: 1. Declares a string containing “Hello Azure!" 2. Gets a reference to a BlockBlobClient object by calling GetBlockBlobClient on the container from the Create a container section. 3. Uploads the string to the blob by calling the UploadFrom function. This function creates the blob if it doesn't already exist, or updates it if it does. nitps:leam mierosot.comlon-usfazuelstorage/oobsiquicksta-blobs-cplus-plus tabs=managed-dentiy'%2Croles-a2ure-portal arnt‘2124, 5:14 PM (Quickstart: Azur Blob Storage brary - C++ - Azure Storage | Microsoft Learn Add this code to the end of main(): ce std::string blobName = “blob.txt"; uint&_t blobContent[] = "Hello Azure!"; // Create the block blob client BlockBlobClient blobClient = containerClient .GetBlockBlobClient(blobName) ; // Upload the blob std::cout << “Uploading blob: " << blobName << std::endl; blobClient .UploadFrom(blobContent, sizeof(blobContent)); List the blobs in a container List the blobs in the container by calling the ListBlobs _ function. Only one blob has been added to the container, so the operation returns just that blob. ‘Add this code to the end of main() ce std::cout << “Listing blobs..." << std::endl; auto ListBlobsResponse = containerClient .ListBlobs(); for (auto blobItem : listBlobsResponse.Blobs) { std::cout << "Blob name: " << blobIten.Name << std::endl; 3 Download blobs Get the properties of the uploaded blob. Then, declare and resize a new std: :vector
object by using the properties of the uploaded blob. Download the previously created blob into the new std::vectorcuints_t> object by calling the DownloadTo — function in the BlobClient _ base class. Finally, display the downloaded blob data. Add this code to the end of main(): ce nitps:leam mierosot.comlon-usfazuelstorage/oobsiquicksta-blobs-cplus-plus tabs=managed-dentiy'%2Croles-a2ure-portal ont‘22124, 5:14 PM (Quickstart: Azure Blob Storage brary - C++ - Azure Storage | Microsoft Learn auto properties = blobClient.GetProperties() .Value; std: :vector
downloadedBlob(properties.BlobSize); blobClient.DownloadTo(downloadedBlob.data(), downloaded8lob.size()); std::cout << "Downloaded blob contents: " << std: :string(downloadedBlob.begin(), downloadedBlob.end()) << std::endl; Delete a Blob The following code deletes the blob from the Azure Blob Storage container by calling the BlobClient.Delete function. cH std::cout << “Deleting blob: blobClient.Delete(); << blobName << std::endl; Delete a container The following code cleans up the resources the app created by deleting the entire container by using BlobContainerClient.Delete Add this code to the end of main(): ce std::cout << “Deleting container: " << containerName << std::endl; containerClient.Delete(); Run the code This app creates a container and uploads a text file to Azure Blob Storage. The example then lists the blobs in the container, downloads the file, and displays the file contents. Finally, the app deletes the blob and the container. The output of the app is similar to the following example: Output nitps:leam mierosot.comlon-usfazuelstorage/oobsiquicksta-blobs-cplus-plus tabs=managed-dentiy'%2Croles-a2ure-portal sort‘22124, 5:14 PM (Quickstart: Azure Blob Storage brary - C++ - Azure Storage | Microsoft Learn Azure Blob Storage - C++ quickstart sample Creating container: myblobcontainer Uploading blob: blob. txt Listing blobs. Blob name: blob.txt Downloaded blob contents: Hello Azure! Deleting blob: blob. txt Deleting container: myblobcontainer Next steps In this quickstart, you learned how to upload, download, and list blobs using C++. You also learned how to create and delete an Azure Blob Storage container. To see a C++ Blob Storage sample, continue to: nitps:leam mierosot.comlon-usfazuelstorage/oobsiquicksta-blobs-cplus-plus tabs=managed-dentiy'%2Croles-a2ure-portal wt
You might also like
Exam Topics PDF
PDF
No ratings yet
Exam Topics PDF
577 pages
AboutBlobStorage AZURE
PDF
No ratings yet
AboutBlobStorage AZURE
1,785 pages
Module 7
PDF
No ratings yet
Module 7
87 pages
Storage PDF
PDF
100% (1)
Storage PDF
937 pages
Azure Storage PDF
PDF
No ratings yet
Azure Storage PDF
1,305 pages
Az 204 Day 2 en 1731002270460
PDF
No ratings yet
Az 204 Day 2 en 1731002270460
53 pages
Azure Storage PDF
PDF
No ratings yet
Azure Storage PDF
28 pages
Azure Blob Storage Documentation
PDF
100% (1)
Azure Blob Storage Documentation
21 pages
Azure Blob Storage
PDF
No ratings yet
Azure Blob Storage
8 pages
Az 204t00a Enu Powerpoint 03
PDF
No ratings yet
Az 204t00a Enu Powerpoint 03
33 pages
Az 104t00a Enu Powerpoint 07
PDF
No ratings yet
Az 104t00a Enu Powerpoint 07
56 pages
AZ 104T00A ENU PowerPoint - 07
PDF
100% (1)
AZ 104T00A ENU PowerPoint - 07
50 pages
AZ 103T00A ENU PowerPoint - 03
PDF
No ratings yet
AZ 103T00A ENU PowerPoint - 03
46 pages
Azure Blob Storage Client Library For Java
PDF
No ratings yet
Azure Blob Storage Client Library For Java
16 pages
Module - 07 Azure Storage
PDF
No ratings yet
Module - 07 Azure Storage
51 pages
Azure Blob Storage Client Library For Python
PDF
No ratings yet
Azure Blob Storage Client Library For Python
13 pages
AZ 104T00A ENU PowerPoint - 07
PDF
No ratings yet
AZ 104T00A ENU PowerPoint - 07
56 pages
DP 900T00A ENU PowerPoint - 03
PDF
No ratings yet
DP 900T00A ENU PowerPoint - 03
15 pages
Final 3
PDF
No ratings yet
Final 3
70 pages
Lab14 - Understanding Blob Storage - Azure
PDF
No ratings yet
Lab14 - Understanding Blob Storage - Azure
35 pages
Lesson - 03 - Implement and Manage Storage
PDF
No ratings yet
Lesson - 03 - Implement and Manage Storage
61 pages
Azure
PDF
No ratings yet
Azure
10 pages
Storage
PDF
No ratings yet
Storage
15 pages
9780137593132
PDF
No ratings yet
9780137593132
8 pages
Microsoft File
PDF
No ratings yet
Microsoft File
7 pages
Create, Download, and List Blobs With Azure CLI
PDF
No ratings yet
Create, Download, and List Blobs With Azure CLI
6 pages
AZ 104T00A ENU PowerPoint - 07
PDF
No ratings yet
AZ 104T00A ENU PowerPoint - 07
49 pages
Azure Storage Building Blocks
PDF
No ratings yet
Azure Storage Building Blocks
54 pages
Manage Azure Storage
PDF
No ratings yet
Manage Azure Storage
7 pages
Data Storage in WIndows Azure
PDF
No ratings yet
Data Storage in WIndows Azure
34 pages
Blob L100
PDF
No ratings yet
Blob L100
22 pages
05-Create Blob Storage
PDF
No ratings yet
05-Create Blob Storage
4 pages
AZ 104T00A Module - 07
PDF
No ratings yet
AZ 104T00A Module - 07
50 pages
Ws 2.1
PDF
No ratings yet
Ws 2.1
5 pages
5 - Using Azure Storage Explorer
PDF
No ratings yet
5 - Using Azure Storage Explorer
6 pages
4.0 - Working With The Blob Service
PDF
No ratings yet
4.0 - Working With The Blob Service
6 pages
Introduction To Azure Blob Storage
PDF
No ratings yet
Introduction To Azure Blob Storage
6 pages
Module 03 Develop Solutions That Use Blob Storage
PDF
No ratings yet
Module 03 Develop Solutions That Use Blob Storage
30 pages
What Is Azure Blob Storage
PDF
No ratings yet
What Is Azure Blob Storage
2 pages
Azure Storage
PDF
No ratings yet
Azure Storage
4 pages
Azure Blob Storage For File Management
PDF
No ratings yet
Azure Blob Storage For File Management
4 pages
Introduction To Windows Azure Blob Storage
PDF
No ratings yet
Introduction To Windows Azure Blob Storage
19 pages
Azure Basic 17
PDF
No ratings yet
Azure Basic 17
3 pages
3TPN° - 03 - DP-900 - Explore Azure Storage
PDF
No ratings yet
3TPN° - 03 - DP-900 - Explore Azure Storage
4 pages
Azure - Lab 05
PDF
No ratings yet
Azure - Lab 05
11 pages
Azure Basic 18
PDF
No ratings yet
Azure Basic 18
2 pages
Azure Basic 10
PDF
No ratings yet
Azure Basic 10
2 pages
Storing and Consuming Files From Azure Storage
PDF
No ratings yet
Storing and Consuming Files From Azure Storage
26 pages
Azure Basic 14
PDF
No ratings yet
Azure Basic 14
2 pages
(English (Auto-Generated) ) AZ-900 Episode 11 - Azure Storage Services - Blob, Queue, Table, Files, Disk and Storage Tiers (DownSub - Com)
PDF
No ratings yet
(English (Auto-Generated) ) AZ-900 Episode 11 - Azure Storage Services - Blob, Queue, Table, Files, Disk and Storage Tiers (DownSub - Com)
4 pages
Azure Blob Storage Fundamentals - Learn - Microsoft Docs
PDF
No ratings yet
Azure Blob Storage Fundamentals - Learn - Microsoft Docs
2 pages
Practical No.7:understanding and Creating Blob Storage in Windows Azure For Cloud Services
PDF
No ratings yet
Practical No.7:understanding and Creating Blob Storage in Windows Azure For Cloud Services
10 pages
Microsoft Azure - Add Storage Blob Owner Role Assignment For Azure AD User
PDF
No ratings yet
Microsoft Azure - Add Storage Blob Owner Role Assignment For Azure AD User
1 page
Niraj Kumar Lead Azure Architect, MCT (Microsoft Certified Trainer)
PDF
No ratings yet
Niraj Kumar Lead Azure Architect, MCT (Microsoft Certified Trainer)
8 pages
Microsoft Azure - Concept of Blob Versioning in Azure Storage
PDF
No ratings yet
Microsoft Azure - Concept of Blob Versioning in Azure Storage
1 page
Use The Azure Portal To Upload A File To Azure Storage
PDF
No ratings yet
Use The Azure Portal To Upload A File To Azure Storage
2 pages
LAB - Create Blob Storage
PDF
No ratings yet
LAB - Create Blob Storage
3 pages
Create A Load Balancer With More Than One Availability Set in The Backend Pool Using The Azure Portal
PDF
No ratings yet
Create A Load Balancer With More Than One Availability Set in The Backend Pool Using The Azure Portal
21 pages
Create A Gateway Load Balancer Using Azure PowerShell
PDF
No ratings yet
Create A Gateway Load Balancer Using Azure PowerShell
9 pages
Create A Gateway Load Balancer Using The Azure CLI
PDF
No ratings yet
Create A Gateway Load Balancer Using The Azure CLI
9 pages
Azure Win VM Terraform LAB
PDF
No ratings yet
Azure Win VM Terraform LAB
10 pages
Azure DDoS Network Protection
PDF
No ratings yet
Azure DDoS Network Protection
9 pages
Azure VM Overview
PDF
No ratings yet
Azure VM Overview
9 pages
Create A Gateway Load Balancer Using The Azure Portal
PDF
No ratings yet
Create A Gateway Load Balancer Using The Azure Portal
16 pages
Load Balance VMs Within An Availability Zone by Using The Azure Portal
PDF
No ratings yet
Load Balance VMs Within An Availability Zone by Using The Azure Portal
15 pages
Create A Multiple Virtual Machine Inbound NAT Rule Using The Azure Portal
PDF
No ratings yet
Create A Multiple Virtual Machine Inbound NAT Rule Using The Azure Portal
13 pages
Create A Single Virtual Machine Inbound NAT Rule Using The Azure Portal
PDF
No ratings yet
Create A Single Virtual Machine Inbound NAT Rule Using The Azure Portal
13 pages
Identity Integrations
PDF
No ratings yet
Identity Integrations
7 pages
Create An Internal Load Balancer Via CLI
PDF
No ratings yet
Create An Internal Load Balancer Via CLI
12 pages
Create An Internal Load Balancer Via Bicep
PDF
No ratings yet
Create An Internal Load Balancer Via Bicep
7 pages
Configure Outbound Connectivity With A Gateway Load Balancer
PDF
No ratings yet
Configure Outbound Connectivity With A Gateway Load Balancer
7 pages
Migrate From Inbound NAT Pools To NAT Rules
PDF
No ratings yet
Migrate From Inbound NAT Pools To NAT Rules
4 pages
Azure Linux VM Portal LAB
PDF
No ratings yet
Azure Linux VM Portal LAB
7 pages
Zero Trust Principles To An Azure Virtual WAN
PDF
No ratings yet
Zero Trust Principles To An Azure Virtual WAN
17 pages
Integrate With Zero Trust Solutions
PDF
No ratings yet
Integrate With Zero Trust Solutions
1 page
Create A Fully Qualified Domain Name For A VM
PDF
No ratings yet
Create A Fully Qualified Domain Name For A VM
1 page
Use Azure Storage Explorer To Create A Blob
PDF
No ratings yet
Use Azure Storage Explorer To Create A Blob
8 pages
Azure Win VM Portal LAB
PDF
No ratings yet
Azure Win VM Portal LAB
8 pages
DNS Name Resolution
PDF
No ratings yet
DNS Name Resolution
7 pages
Blob Storage Feature Support in Azure Storage Accounts
PDF
No ratings yet
Blob Storage Feature Support in Azure Storage Accounts
6 pages
Virtual Machine With A Static Public IP Address
PDF
No ratings yet
Virtual Machine With A Static Public IP Address
4 pages
Recover Deleted Storage Account
PDF
No ratings yet
Recover Deleted Storage Account
3 pages