Introducing the new Azure SDK for C++
source link: https://devblogs.microsoft.com/azure-sdk/intro-cpp-sdk/?WT_mc_id=DOP-MVP-4025064
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Introducing the new Azure SDK for C++
June 28th, 2021
This month, the Azure SDK team released the new Azure SDK for C++, starting with Azure Core, Identity, and Storage Blobs, Files Shares, and Datalake. We’re excited to share our guides to getting started and working with the latest libraries!
Getting the latest libraries
You can find all of the latest source code on the official Azure SDK for C++ repository. Additionally, the following packages are available to install via vcpkg:
Name
Latest Version
Replaces
azure-core-cpp
1.0.0
–
azure-identity-cpp
1.0.0
–
auzre-storage-common-cpp
12.0.0
azure-storage-cpp 7.5.0
azure-storage-blobs-cpp
12.0.0
azure-storage-cpp 7.5.0
azure-storage-files-shares-cpp
12.0.0
azure-storage-cpp 7.5.0
azure-storage-files-datalake-cpp
12.0.0
azure-storage-cpp 7.5.0
Similar to the Azure SDKs for .NET, Java, JavaScript/TypeScript, and Python, the latest Azure SDK for C++ is divided into smaller libraries that allow for greater control when linking and developing.
At this time, we maintain support for desktop triplets, including:
- x86-windows
- x64-windows
- x64-linux
- x64-osx
Installing the Azure Storage library
Downloading the Azure Storage Blobs, Files Shares, and Datalake libraries through vcpkg is as simple as running the following command:
vcpkg install azure-storage-blobs-cpp[:<triplet>] azure-storage-files-shares-cpp[:<triplet>] azure-storage-files-datalake-cpp:[:<triplet>]
Alternatively, developers are welcome to download source code from the Azure SDK for C++ repository and compile the code directly using the provided CMAKE files.
Getting Started with Azure Storage for C++
The Azure SDK for C++ supports linking with CMAKE by including the following lines in your CMakeLists.txt
file:
find_package(azure-storage-blobs-cpp CONFIG REQUIRED)
target_link_libraries(<your project name> PRIVATE Azure::azure-storage-blobs)
find_package(azure-storage-files-shares-cpp CONFIG REQUIRED)
target_link_libraries(<your project name> PRIVATE Azure::azure-storage-blobs)
Listing blobs in a container
The following snippet creates a BlobContainerClient
, which connects with the Azure Storage service, and then lists the blobs in a container using the containerClient
object. Note that in this snippet, the connection string is a secret that has been stored in an environment variable and should not be shared.
#include <azure/storage/blobs.cpp>
using namespace Azure::Storage::Blobs;
std::string connectionString = get_env("AZURE_STORAGE_CONNECTION_STRING");
std::string containerName = "mycontainer";
BlobContainerClient containerClient = BlobContainerClient::CreateFromConnectionString(connectionString, containerName);
auto listBlobsResponse = containerClient.ListBlobs();
for (auto blobItem : listBlobsResponse.Blobs)
{
std::cout << "Blob name: " << blobItem.Name << std::endl;
}
Uploading a file to an Azure Files Share
To upload a file to the files share, we create a ShareClient
, which connects with the Azure Storage service, and then a ShareFileClient
to upload the file contents. Note again, in this snippet the connection string has been stored in an environment variable.
#include <azure/storage/files/shares.hpp>
using namespace Azure::Storage::Files::Shares;
std::string connectionString = get_env("AZURE_STORAGE_CONNECTION_STRING");
std::string shareName = "myshare";
std::string fileName = "myfile";
std::string fileContent = "Hello Azure!";
auto shareClient = ShareClient::CreateFromConnectionString(connectionString, shareName);
shareClient.CreateIfNotExists();
ShareFileClient fileClient = shareClient.GetRootDirectoryClient().GetFileClient(fileName);
fileClient.UploadFrom(reinterpret_cast<const uint8_t*>(fileContent.data()), fileContent.size());
More Samples
To see a full scenario for the Azure SDKs for C++, visit the official Azure SDK for C++ repository or go to Microsoft Docs. To get you started quickly, you can visit the following quickstarts and samples:
SDK
Quickstart on Docs
Samples on GitHub
azure-storage-blobs-cpp
azure-storage-files-shares-cpp
azure-storage-files-datalake-cpp
–
Consistent and Idiomatic
Developers familiar with our other Azure Storage libraries might notice the recurrence of the Azure::Storage::Blobs::BlobContainerClient or Azure::Storage::Files::Shares::ShareClient classes. In accordance with our General Guidelines, we aim for a developer experience that is both consistent with the Azure Storage libraries for our currently released libraries as well as idiomatic to the C++ standards so that developers are supported regardless of the programming language.
Support, Feedback, Feature Requests, and Bug Reporting
The easiest way to get in touch with our development team is to open an issue on the official Azure SDK for C++ repository. We regularly triage new issues; for more information about our GitHub process, check out Lily Ma’s blog post Azure SDK GitHub Support Process.
Azure SDK Blog Contributions
Thank you for reading this Azure SDK blog post! We hope that you learned something new and welcome you to share this post. We are open to Azure SDK blog contributions. Please contact us at [email protected] with your topic and we’ll get you set up as a guest blogger.
Azure SDK Links
Kyle Patterson
Program Manager, Azure SDK
Follow
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK