Best way to load uint8_t array into azure blob storage with wastorage in C ++
I would like to load the uint8_t array into azure storage using the azure storage SDK. I'm trying to build an input stream from an array, I was able to get something compiled with std :: vector, but which requires an extra copy of the array.
What do you think is the best 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();
}
upload_from_stream method requires concurrency :: streams :: istream but I don't know how to build if from underlying array
thank you in advance
+1
source to share
1 answer
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();
}
+3
source to share