0

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

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

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

我使用的是 Windows 8.1 和最新版本的 Winzip。这在开发和生活环境中都会发生。这里有什么问题?

更新 14/01/2014 这是我使用的代码

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
4

1 回答 1

1

请更改以下代码行:

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

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

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

于 2014-01-14T10:11:17.383 回答