#include #include #include #include #include "storage_credential.h" #include "storage_account.h" #include "blob/blob_client.h" static std::string account_name = "YOUR_ACCOUNT_NAME"; // Provide either account key or access token // Account key operations require RBAC 'Storage Blob Data Owner' static std::string account_key = ""; // Storage account key if using shared key auth static std::string access_token = ""; // Get an access token via `az account get-access-token --resource https://storage.azure.com/ -o tsv --query accessToken` using namespace azure::storage_lite; void checkstatus() { if(errno == 0) { printf("Success\n"); } else { printf("Fail\n"); } } int main() { std::shared_ptr cred = nullptr; if (!access_token.empty()) { cred = std::make_shared(access_token); } else { cred = std::make_shared(account_name, account_key); } std::shared_ptr account = std::make_shared(account_name, cred, /* use_https */ true); auto bC = std::make_shared(account, 10); //auto f1 = bc.list_containers(""); //f1.wait(); // std::string containerName = "jasontest1"; std::string blobName = "test.txt"; std::string destContainerName = "jasontest1"; std::string destBlobName = "test.txt.copy"; std::string uploadFileName = "test.txt"; std::string downloadFileName = "download.txt"; bool exists = true; blob_client_wrapper bc(bC); exists = bc.container_exists(containerName); if(!exists) { bc.create_container(containerName); assert(errno == 0); } assert(errno == 0); exists = bc.blob_exists(containerName, "testsss.txt"); assert(errno == 0); assert(!exists); std::cout <<"Start upload Blob: " << blobName << std::endl; bc.upload_file_to_blob(uploadFileName, containerName, blobName); std::cout <<"Error upload Blob: " << errno << std::endl; assert(errno == 0); exists = bc.blob_exists(containerName, blobName); assert(errno == 0); assert(exists); auto blobProperty = bc.get_blob_property(containerName, blobName); assert(errno == 0); std::cout <<"Size of BLob: " << blobProperty.size << std::endl; auto blobs = bc.list_blobs_segmented(containerName, "/", "", ""); std::cout <<"Size of BLobs: " << blobs.blobs.size() << std::endl; std::cout <<"Error Size of BLobs: " << errno << std::endl; assert(errno == 0); time_t last_modified; bc.download_blob_to_file(containerName, blobName, downloadFileName, last_modified); std::cout <<"Download Blob done: " << errno << std::endl; assert(errno == 0); exists = bc.container_exists(destContainerName); if(!exists) { bc.create_container(destContainerName); assert(errno == 0); } // copy blob bc.start_copy(containerName, blobName, destContainerName, destBlobName); auto property = bc.get_blob_property(destContainerName, destBlobName); std::cout << "Copy status: " << property.copy_status <