1

I would like to upload a uint8_t array to azure storage using the azure storage SDK. I m struggling to construct the input stream from the array, I managed to get something that compile by using a std::vector but that require an extra copy of the array.

Do you think of a better way?

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();
}

the upload_from_stream method requieres a concurrency::streams::istream but I don't know how to construct if from a basic array

thank you by advance

fred_
  • 1,486
  • 1
  • 19
  • 31

1 Answers1

4

I managed to find a better solution using 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();

}
fred_
  • 1,486
  • 1
  • 19
  • 31
  • Thanks for the solution. I encountered the same problem and used your approach. However, I got an std::runtime_error when create_istream from the buffer, with error message "stream buffer not set up for input of data". I wonder if you saw any problems like this before or have any insights. Thanks! – Thompson Liu Apr 07 '21 at 00:49
  • may be your "data" is empty? I have no answer, I m using .NET 5 now to upload to blob storage! – fred_ Apr 07 '21 at 14:46
  • I see. I haven't solved it, but it turns out that the CPP library that I used is deprecated soon, so I changed to a different library that is much easier to work with. – Thompson Liu Apr 07 '21 at 17:39