我正在尝试从asp.net核心将图像上传到blob容器,但是我看到在blob容器中上传图像后该图像为零字节。我在Google中搜索以解决问题并设置position = 0(即使仍然存在问题),有人找到我错了的地方吗?
这是我正在使用的代码。
public async Task AddFace(IFormFile file)
{
dynamic FileExtension = string.Empty;
if (file.Length > 0)
{
FileExtension = Path.GetExtension(file.FileName);
if (string.IsNullOrEmpty(FileExtension))
{
FileExtension = ".jpg";
}
using (Stream stream = file.OpenReadStream())
{
stream.Seek(0, SeekOrigin.Begin);
//UPLOAD TO BLOB CONTAINER
CloudStorageAccount account = CloudStorageAccount.Parse(ConnectionString);
CloudBlobClient blobClient = account.CreateCloudBlobClient();
CloudBlobContainer blobContainer = blobClient.GetContainerReference(configuration[ConfigKeys.BlobStorageConfiguration.BlobContainer]);
CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference(file.FileName+FileExtension );
await blockBlob.UploadFromStreamAsync(stream);
}
}
}