我已经建立了一个Azure Blob Storage以上传/下载文件。请参考此链接配置您的存储连接字符串。
ProcessAsync(Folderpath, rows.Item("FileName"), rows.Item("Extension")).GetAwaiter().GetResult()
System.IO.File.Move(Folderpath + "\" + rows.Item("FileName"), AchivePath + "\" + rows.Item("FileName"))
WriteToLog("Extracted File : " + rows.Item("FileName") + " ", "")
DownloadBlobSnapshot(rows.Item("FileName"), rows.Item("Extension")).GetAwaiter().GetResult()
目前,我能够将文件存储在我的桌面上。如何使用 .net MVC
平台和 Using 和 MemoryStream/FileStream 将文件保存并显示出来?
或者,是否有更好的方法来完成这个任务?
编辑 1:(基于 Ivan 的答案)
Private Shared Async Function DownloadBlobSnapshot(FileName As String, Extension As String) As Task
Dim storageAccount As CloudStorageAccount
Dim storageConnectionString As String = ConfigurationManager.AppSettings("StorageConnectionString")
Dim accountName As String = myaccountname
Dim accountKey As String = myaccountkey
Dim cred = New StorageCredentials(accountName, accountKey)
Dim account = New CloudStorageAccount(cred, True)
Dim client = account.CreateCloudBlobClient()
Dim container = client.GetContainerReference(FileName.Replace(Extension, ""))
Dim listOfBlobs As IEnumerable = container.ListBlobs(Nothing, True, BlobListingDetails.Snapshots)
If CloudStorageAccount.TryParse(storageConnectionString, storageAccount) Then
For Each item In listOfBlobs
Dim blockBlob As CloudBlockBlob = container.GetBlockBlobReference((CType(item, CloudBlockBlob)).Name)
blockBlob.DownloadToStream(Response.OutputStream)
Next
//ToDO
End If
End Function
但是我意识到Response
在Shared
函数中不可用。