0

WinZip を使用して zip ファイルを作成しました。これは、WinZip と Windows エクスプローラーの両方を使用して開くことができます。

次に、このファイルを Azure Storage にアップロードし、再度ダウンロードします。

ダウンロードしたファイルを Windows エクスプローラーで開くことはできますが、WinZip でファイルが破損していると表示されます。

Windows 8.1 と最新バージョンの Winzip を使用しています。これは、開発環境とライブ環境の両方で発生します。ここで何が問題なのですか?

UPDATE 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())

最後のバイトを見逃しているため、ブロブが完全にダウンロードされていません。

于 2014-01-14T10:11:17.383 に答える