Я не могу полностью понять ваш код, поскольку текущий BlobClient версии v11.1.1 не предоставляет никаких методов загрузки. Как упоминалось в @ Guarav Mantri-AIS , readAsync
может вести себя подобным образом.
Рассмотрите альтернативу, используя DownloadToByteArrayAsync()
, который является частью API. Я включил код, необходимый для подключения, но, конечно, это просто для демонстрации полного примера.
Ваш метод будет сокращен следующим образом:
public async Task<byte[]> GetFile(string containerName, string fileName)
{
//i am getting the container here, not sure where or how you are doing this
var container = GetContainer("//your connection string", containerName);
//Get the blob first
ICloudBlob blob = container.GetBlockBlobReference(fileName);
//and now download it straight to a byte array
return await blobClient.DownloadAsync();
}
public CloudBlobContainer GetContainer(string connectionString, string containerName)
{
//1. connect to the account
var account = CloudStorageAccount.Parse(connectionString);
//2. create a client
var blobClient = _account.CreateCloudBlobClient();
//3. i am getting the container here, not sure where or how you are doing this
return = _blobClient.GetContainerReference(containerName);
}