azure存储上传zip文件,然后再次下载并且它已损坏

时间:2014-01-13 16:40:13

标签: azure zip storage winzip

我使用WinZip创建了一个zip文件。我可以使用WinZip和Windows资源管理器打开它。

然后我将此文件上传到Azure存储,然后再次下载。

我可以在Windows资源管理器中打开下载的文件,但WinZip说它已损坏。

我使用的是Windows 8.1和最新版本的Winzip。这在开发和实时环境中都会发生。这有什么不对?

更新2014年1月14日 这是我使用的代码

Private Sub UploadDocumentToAzure(filename As String, _
                                  ByRef stream As Stream)
    Dim storageAccount As CloudStorageAccount = CloudStorageAccount.Parse(Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting("StorageConnectionString"))
    Dim blobClient As CloudBlobClient = storageAccount.CreateCloudBlobClient
    Dim container As CloudBlobContainer = blobClient.GetContainerReference("cont")

    container.CreateIfNotExists()

    Dim blockBlob As CloudBlockBlob = container.GetBlockBlobReference(filename)
    blockBlob.UploadFromStream(stream)
End Sub

Public Sub DownloadDocumentFromAzure(documentName As String, ByRef response As HttpResponse)

    Dim storageAccount As CloudStorageAccount = CloudStorageAccount.Parse(Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting("StorageConnectionString"))
    Dim blobClient As CloudBlobClient = storageAccount.CreateCloudBlobClient
    Dim container As CloudBlobContainer = blobClient.GetContainerReference("cont")

    Dim blockBlob As CloudBlockBlob = container.GetBlockBlobReference(documentName)

    Dim memStream As New MemoryStream
    blockBlob.DownloadToStream(memStream)

    response.ContentType = blockBlob.Properties.ContentType
    response.AddHeader("Content-Disposition", "Attachment; filename=""" & blockBlob.Name.ToString() & """")

    response.AddHeader("Content-Length", (blockBlob.Properties.Length - 1).ToString())
    response.BinaryWrite(memStream.ToArray())
    response.End()
End Sub

1 个答案:

答案 0 :(得分:1)

请更改以下代码行:

response.AddHeader("Content-Length", (blockBlob.Properties.Length - 1).ToString())

response.AddHeader("Content-Length", (blockBlob.Properties.Length).ToString())

因为你错过了最后一个字节,所以你的blob没有完全下载。