I tried the sample.cpp provided with a little modification for logging and error checking. Please see below code. I gave correct credentials, the container and blob which i am trying to download exist and i could successfully download blob from blob storage.
But, i get error while creating storage_account, blob_client, blob client wrapper though my credentials are correct. I checked 'errno' variable. Please see the code and guide me if i am using it in a wrong way.
void checkstatus()
{
if(errno == 0)
{
printf("Success\n");
}
else
{
printf("Failure\n");
}
}
int main()
{
std::shared_ptr<storage_credential> cred = nullptr;
cred = std::make_shared<shared_key_credential>(account_name, account_key);
printf("\nCreating account : ");
std::shared_ptr<storage_account> account = std::make_shared<storage_account>(account_name, cred, /* use_https */ true);
checkstatus();
if(NULL != account)
{
printf("\nCreating blob client : ");
auto bC = std::make_shared<blob_client>(account, 2);
checkstatus();
std::string containerName = "con1";
std::string blobName = "1.txt";
bool exists = true;
printf("\nCreating blob client wrapper : ");
blob_client_wrapper bc(bC);
checkstatus();
printf("\nGet blob property: ");
bc.get_blob_property(containerName, blobName);
checkstatus();
printf("\nChecking does container exist: ");
exists = bc.container_exists(containerName);
checkstatus();
printf("\nChecking does blob exist: ");
exists = bc.blob_exists(containerName, "1.txt");
checkstatus();
if(!exists)
{
printf("\n Blob name does not exist");
}
time_t last_modified;
printf("\nDownloading file");
bc.download_blob_to_file(containerName, blobName, "./13.txt", last_modified);
std::cout <<"Download Blob done: " << errno << std::endl;
}
else
{
std::cout <<"Download Error: " << errno << std::endl;
}
return 0;
}
I tried the sample.cpp provided with a little modification for logging and error checking. Please see below code. I gave correct credentials, the container and blob which i am trying to download exist and i could successfully download blob from blob storage.
But, i get error while creating storage_account, blob_client, blob client wrapper though my credentials are correct. I checked 'errno' variable. Please see the code and guide me if i am using it in a wrong way.