* Give AccessTier a default value to eliminate warning * Add blob clients conversion functions * Fix bug in shared key authentication * Add GetUri(). * make lease-status and lease-state optional * Check duplicates in metadata * add tests for blob service * AppendBlocb doesn't support AccessTier * fix bug in "RangeFromXml" * redefine PageRange in convenience layer * suppress warnings from gtest * add API AppendBlockFromUri * connection string parsing * Add memorystream * Rename connection string constants * Adapt to new bodystream, this will be rewritten when bosystream is changed to unique_ptr * fix compiler errors * Change MemoryStream interface * samples framework * Add newline at the end of file * fix compiler error
50 lines
1.5 KiB
C++
50 lines
1.5 KiB
C++
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#include "blobs/blob.hpp"
|
|
#include "samples_common.hpp"
|
|
|
|
#include <iostream>
|
|
|
|
SAMPLE(BlobsGettingStarted, BlobsGettingStarted)
|
|
void BlobsGettingStarted()
|
|
{
|
|
using namespace Azure::Storage::Blobs;
|
|
|
|
std::string containerName = "sample-container";
|
|
std::string blobName = "sample-blob";
|
|
std::string blobContent = "Hello Azure!";
|
|
|
|
auto containerClient
|
|
= BlobContainerClient::CreateFromConnectionString(GetConnectionString(), containerName);
|
|
try
|
|
{
|
|
containerClient.Create();
|
|
}
|
|
catch (std::runtime_error& e)
|
|
{
|
|
// The container may already exist
|
|
std::cout << e.what() << std::endl;
|
|
}
|
|
|
|
BlockBlobClient blobClient = containerClient.GetBlockBlobClient(blobName);
|
|
|
|
auto blobContentStream = new Azure::Storage::MemoryStream(
|
|
reinterpret_cast<const uint8_t*>(blobContent.data()), blobContent.length());
|
|
blobClient.Upload(blobContentStream);
|
|
|
|
std::map<std::string, std::string> blobMetadata = {{"key1", "value1"}, {"key2", "value2"}};
|
|
blobClient.SetMetadata(blobMetadata);
|
|
|
|
auto blobDownloadContent = blobClient.Download();
|
|
blobContent.resize(static_cast<std::size_t>(blobDownloadContent.BodyStream->Length()));
|
|
blobDownloadContent.BodyStream->Read(reinterpret_cast<uint8_t*>(&blobContent[0]), blobContent.length());
|
|
std::cout << blobContent << std::endl;
|
|
|
|
auto properties = blobClient.GetProperties();
|
|
for (auto metadata : properties.Metadata)
|
|
{
|
|
std::cout << metadata.first << ":" << metadata.second << std::endl;
|
|
}
|
|
}
|