将 uint8_t 数组上传到 Azure Blob 存储的最佳方法,在 C++ 中浪费

best way to upload uint8_t array to azure blob storage with wastorage in c++

我想使用 azure 存储 SDK 将 uint8_t 数组上传到 azure 存储。我正在努力从数组构造输入流,我设法通过使用 std::vector 获得了一些编译的东西,但这需要数组的额外副本。

你有没有想到更好的办法?

void upload(azure::storage::cloud_blob_container container, const wchar_t* blobName, const uint8_t * data, size_t dataLength) {

    std::vector<uint8_t> bytes(dataLength, (const unsigned char)data);
    concurrency::streams::bytestream byteStream = concurrency::streams::bytestream();
    concurrency::streams::istream inputStream = byteStream.open_istream(bytes);

    const utility::string_t myBlobName(blobName);
    azure::storage::cloud_block_blob blockBlob = container.get_block_blob_reference(myBlobName);
    blockBlob.upload_from_stream(inputStream);

    inputStream.close();
}

upload_from_stream 方法需要 concurrency::streams::istream 但我不知道如何从基本数组构建 if

提前致谢

我设法使用 rawptr_buffer 找到了更好的解决方案:

void BlobService::upload(cloud_blob_container container, const wchar_t* blobName, const uint8_t * data, size_t dataLength) {

    rawptr_buffer<uint8_t> buffer(data, dataLength);
    istream inputStream = buffer.create_istream();

    cloud_block_blob blob = container.get_block_blob_reference(utility::string_t(blobName));
    blob.upload_from_stream(inputStream);

    inputStream.close().wait();
    buffer.close().wait();

}