Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

download_to_stream() gives code "NotFoundError" even though blob exists  #408

@drd2021

Description

@drd2021

Using azure-storage-cpp (probably v7.4) on Linux, I am trying to download a binary file into a std::vector<uint8_t>. The file exists under the container "testcontainer". Why does the function download_to_stream() fails with error code "NotFoundError"?

Here's my code and the output below:

Code:

        const utility::string_t storage_connection_string(U("DefaultEndpointsProtocol=https;AccountName=<my_account>;AccountKey=<my_key>"));
        azure::storage::cloud_storage_account storage_account = azure::storage::cloud_storage_account::parse(storage_connection_string);
        azure::storage::cloud_blob_client blob_client = storage_account.create_cloud_blob_client();
        azure::storage::cloud_blob_container container = blob_client.get_container_reference(_XPLATSTR("testcontainer"));
        sout << "Container name? " << container.name() << "\n";
        sout << "Container successfully created? " << container.create_if_not_exists() << "\n";
        azure::storage::continuation_token token;
        do {
                azure::storage::list_blob_item_segment result = container.list_blobs_segmented(token);
                for (auto& item : result.results()){
                        if (item.is_blob()){
                                sout << "Blob: " << item.as_blob().uri().primary_uri().to_string() << "\n";
                                sout << "Blob name: " << item.as_blob().name() << "\n";
                                sout << "Blob uri path: " << item.as_blob().uri().path() << "\n";
                                sout << "Blob content type: " << item.as_blob().properties().content_type() << "\n";
                                auto binary_blob = container.get_block_blob_reference(item.as_blob().name());
                                concurrency::streams::container_buffer<std::vector<uint8_t>> buffer;
                                concurrency::streams::ostream output(buffer);
                                binary_blob.download_to_stream(output);
                                sout << "Stream: " << utility::string_t(buffer.collection().begin(), buffer.collection().end()) << "\n";
                        }
                        else {
                                sout << "Directory: " << item.as_blob().uri().primary_uri().to_string() << "\n";
                        }
                }
                token = result.continuation_token();
        } while (!token.empty());

Output:

Container name? testcontainer
Container successfully created? 0
Blob: https://<my_account>.blob.core.windows.net/testcontainer/0b8ba7c0ef5e37733617c1a95b866aa378b102fdc34e23cc523ca8a5d3acf7f4
Blob name: 0b8ba7c0ef5e37733617c1a95b866aa378b102fdc34e23cc523ca8a5d3acf7f4
Blob uri path: /testcontainer/0b8ba7c0ef5e37733617c1a95b866aa378b102fdc34e23cc523ca8a5d3acf7f4
Blob content type: application/octet-stream
Stream: {
    "error": {
        "message": "File \"0b8ba7c0ef5e37733617c1a95b866aa378b102fdc34e23cc523ca8a5d3acf7f4\" not found",
        "code": "NotFoundError"
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions