Если вы хотите узнать, сколько байт было загружено, вы можете использовать метод UploadFromStreamAsync
в sdk Microsoft.Azure.Storage.Blob
. Он будет обрабатывать класс StorageProgress
, который содержит информацию о ходе передачи данных для потоков запросов и ответов в одной операции.
![enter image description here](https://i.stack.imgur.com/wWg97.png)
Например
Sub Main()
Dim fileName As String = "D:\\help.txt"
Dim result = isUploaded(fileName).Result
Console.WriteLine(result)
Console.ReadLine()
End Sub
Public Async Function isUploaded(ByVal filename As String) As Task(Of Boolean)
Try
Dim connectionString As String = ""
Dim containerName As String = "test"
Dim storageAccount As CloudStorageAccount = CloudStorageAccount.Parse(connectionString)
Dim blobClient As CloudBlobClient = storageAccount.CreateCloudBlobClient()
Dim container As CloudBlobContainer = blobClient.GetContainerReference(containerName)
Dim blockBlob As CloudBlockBlob = container.GetBlockBlobReference(Path.GetFileName(filename).ToString)
// Define the function how to handle the infromation
Dim handelr As Action(Of StorageProgress) = Sub(progress) Console.WriteLine("Progress: {0} bytes transferred", progress.BytesTransferred)
Dim progressHandler As IProgress(Of StorageProgress) = New Progress(Of StorageProgress)(handelr)
Dim cancellationToken As CancellationToken = New CancellationToken()
Using FileStream = File.OpenRead(filename)
Await blockBlob.UploadFromStreamAsync(FileStream,
New AccessCondition(),
New BlobRequestOptions(),
New OperationContext(),
progressHandler,
cancellationToken)
Return True
End Using
Catch ex As Exception
Return False
MsgBox(ex.Message)
End Try
End Function
![enter image description here](https://i.stack.imgur.com/duGG7.png)