我正在使用VB.Net构建文件上传功能到Microsoft Azure Blob存储。有没有一种方法可以在不使用Microsoft的数据传输库的情况下跟踪数据传输的进度?这是我的代码:
Public Function isUploaded(ByVal filename As String) As Boolean
Try
Dim connectionString As String = "Connection String Here"
Dim containerName As String = "uploads"
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)
Using FileStream = System.IO.File.OpenRead(filename)
blockBlob.UploadFromStream(FileStream)
Return True
End Using
Catch ex As Exception
Return False
MsgBox(ex.Message)
End Try
End Function
如果想知道已经上传了多少字节,则可以使用sdk UploadFromStreamAsync
中的方法UploadFromStreamAsync
。它将处理类Microsoft.Azure.Storage.Blob
,该类在单个操作中保存有关请求和响应流的进度数据传输的信息。
例如
StorageProgress