ZipArchive gives Unexpected end of data corrupted error

六月ゝ 毕业季﹏ 提交于 2019-12-01 02:49:53

Move zipStream.ToArray() outside of the zipArchive using.

The reason for your problem is that the stream is buffered. There's a few ways to deal wtih it:

  • You can set the stream's AutoFlush property to true.
  • You can manually call .Flush() on the stream.

Or, since it's MemoryStream and you're using .ToArray(), you can simply allow the stream to be Closed/Disposed first (which we've done by moving it outside the using).

I was also having problems with this and I found my issue was not the generation of the archive itself but rather how I was handing my GET request in AngularJS.

This post helped me: how to download a zip file using angular

The key was adding responseType: 'arraybuffer' to my $http call.

factory.serverConfigExportZIP = function () {
    return $http({
        url: dataServiceBase + 'serverConfigExport',
        method: "GET",
        responseType: 'arraybuffer'
    })
};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!