Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
drd2021 opened this issue Oct 4, 2021 · 1 comment
Open

Comments

@drd2021
Copy link

drd2021 commented Oct 4, 2021

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"
    }
}

@drd2021 drd2021 changed the title download_to_stream() gives code "NotFoundError" although blob exists download_to_stream() gives code "NotFoundError" even though blob exists Oct 4, 2021
@Jinming-Hu
Copy link
Member

I tried with 7.4.0 release (100c4d8). It works for me

Container name? testcontainer
Container successfully created? 0
Blob: https://ACCOUNT.blob.core.windows.net/testcontainer/0b8ba7c0ef5e37733617c1a95b866aa378b102fdc34e23cc523ca8a5d3acf7f4
Blob name: 0b8ba7c0ef5e37733617c1a95b866aa378b102fdc34e23cc523ca8a5d3acf7f4
Blob uri path: /testcontainer/0b8ba7c0ef5e37733617c1a95b866aa378b102fdc34e23cc523ca8a5d3acf7f4
Blob content type: application/octet-stream
Stream: Hello Azure!

Can you go to Azure Portal and check if the blob actually exists and is not deleted?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants