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

十年热恋 提交于 2019-12-11 12:47:56

问题


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


回答1:


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

}


来源:https://stackoverflow.com/questions/34434361/best-way-to-upload-uint8-t-array-to-azure-blob-storage-with-wastorage-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!