Invalid MVC Core ZipArchive

I create a zip file in a web API call under MVC Core, but Windows cannot open the resulting file, claiming it is invalid.

Here is the code to create the archive:

ZipArchive archive = new ZipArchive( archiveMS, ZipArchiveMode.Create, true );

// loop over a series of Azure blobs which contain text
foreach( BlobPathInfo curBPI in model.Paths )
{
    // AzureBlobFile is a wrapper for CloudBlockBlob
    AzureBlobFile blobFile = blobFolder.File( curBPI.BlobPath.FileName );
    Stream blobStream = blobFile.OpenRead();

    ZipArchiveEntry entry = archive.CreateEntry( zipFolderPath.ToString() );

    using( Stream zipStream = entry.Open() )
    {
        blobStream.CopyTo( zipStream );
    }
}

archive.Dispose();
archiveMS.Seek( 0, SeekOrigin.Begin );

return new FileStreamResult( archiveMS, "application/zip" );

This WebAPI method is called from an angular script and converted to a client side blob associated with the element:

// downloadFiles does a POST request and returns a promise
downloadFiles( params )
.then( function( success ) {
    var linkElement = document.createElement( 'a' );
    var blob = new Blob( [success.data], { type: 'application/zip' } );
    var url = window.URL.createObjectURL( blob );

    linkElement.setAttribute( 'href', url );
    linkElement.setAttribute( 'download', fileName );

    var clickEvent = new MouseEvent( 'click',
    {
        view: window,
        bubbles: true,
        cancelable: false
    } );

    linkElement.dispatchEvent( clickEvent );

All this works in that the archive is created on the server, downloaded to the client, and then saved in the file save dialog box. But the resulting archive on disk is invalid for Windows.

The Windows error message is not useful, basically just declaring that the file is invalid. But I noticed two other things that could be significant:

1) zip- - - Windows (, , , /).

2) :

: : IIS Express :
1/31/2017 4:20:15 PM : 2264 : :
: : N/A :
Muddlehead : , C:\Users\Mark\AppData\Local\Temp\iisexpress\IIS \Clr4IntegratedAppPool . . Xml:
         2264     3     0     0x80000000000000          90672                          C:\Users\Mark\AppData\Local\Temp\iisexpress\IIS \Clr4IntegratedAppPool     03000000

, ?

+4

Source: https://habr.com/ru/post/1668465/


All Articles