I am using Azure Datastorage Gen2 and I have came across problem that I cannot create virtual directory when Hierarchical namespace option is enabled.
If I try to do this
const std::string blobContent= "";
auto blockBlobClient= std::make_shared<Azure::Storage::Blobs::BlockBlobClient>(m_container->GetBlobClient(blobName).AsBlockBlobClient());
std::vector<uint8_t> buffer(blobContent.begin(), blobContent.end());
blockBlobClient->UploadFrom(buffer.data(), buffer.size());
Azure::Storage::Metadata blobMetadata= {{"hdi_isfolder", "true"}};
blockBlobClient->SetMetadata(blobMetadata);
I am getting error *Error: 400 One of the HTTP headers specified in the request is not supported. * But isn't that a way how to create a virtual directory? Can someone please explain me what am I doing wrong?
Thanks!
I have tried to create virtual directory in ADLS Gen2 blob storage
I got Error: 400 One of the HTTP headers specified in the request is not supported
I expected folder to be created without any problems
to create virtual directory in ADLS Gen2 blob storage
You can use the below code to create directory in Azure Data Lake Gen2 blob storage using C++.
To create directory, you need to install azure datalake gen2 package using below command.
vcpkg install azure-storage-files-datalake-cpp
Code:
#include <cstdio>
#include <iostream>
#include <stdexcept>
#include <azure/storage/files/datalake.hpp>
int main()
{
using namespace Azure::Storage::Files::DataLake;
const std::string fileSystemName = "test";
const std::string directoryName = "sample-directory";
const std::string connectionString = "DefaultEndpointsProtocol=https;AccountName=venkat78901;AccountKey=52ZxzzzEZCvozzzzzzzzzzAStAvgrmA==;EndpointSuffix=core.windows.net";
auto fileSystemClient
= DataLakeFileSystemClient::CreateFromConnectionString(connectionString, fileSystemName);
fileSystemClient.CreateIfNotExists();
// Create a directory.
auto directoryClient = fileSystemClient.GetDirectoryClient(directoryName);
directoryClient.Create();
std::cout << "Directory created: " << directoryName << std::endl;
return 0;
}
The above executed and created directory in my container.
Output:
Directory created: sample-directory
Portal: