adding to azure blob storage with stream

天大地大妈咪最大 提交于 2019-12-06 07:43:31

There seems to be some issue when trying to write directly from the stream. I was able to run the code by converting the stream to a byte array.

await blockBlob.UploadFromByteArrayAsync(ReadFully(fileStream, blockBlob.StreamWriteSizeInBytes),
                            0, (int)fileStream.Length);

The ReadFully was a modification over this answer https://stackoverflow.com/a/221941

static byte[] ReadFully(Stream input, int size)
{
    byte[] buffer = new byte[size];
    using (MemoryStream ms = new MemoryStream())
    {
        int read;
        while ((read = input.Read(buffer, 0, size)) > 0)
        {
            ms.Write(buffer, 0, read);
        }
        return ms.ToArray();
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!