I am trying to upload a document into Azure Blob but it throws an error as below while reading the file stream.
Error,
Cannot access a disposed object.
Object name: 'FileBufferingReadStream'.
The error comes when the code OpenReadStream() called,
public async Task UploadAsync(IFormFileCollection files, string directoryName)
{
var blobContainer = await _azureBlobConnectionFactory.GetBlobContainer();
CloudBlobDirectory directory = blobContainer.GetDirectoryReference(directoryName);
for (int i = 0; i < files.Count; i++)
{
CloudBlockBlob blockblob = directory.GetBlockBlobReference(files[i].FileName);
using (var stream = files[i].OpenReadStream())
{
await blockblob.UploadFromStreamAsync(stream);
}
}
}
I am calling the UploadAsync method from my actual service classs like,
public async Task<bool> UploadToBlob(DocumentModel model,string directorypath)
{
try
{
//string directory = directorypath + model.EmailId + "/" + model.Files[0].FileName;
await _blobService.UploadAsync(model.Files, "Documents/dummy.pdf");
return true;
}
catch(Exception e)
{
throw e;
}
}
Where I did go wrong?