その場で圧縮するための私のwebapiメソッドは、このコードを使用します
var result = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new PushStreamContent((stream, content, arg3) =>
{
using (var zipEntry = new Ionic.Zip.ZipFile())
{
using (var ms = new MemoryStream())
{
_xmlRepository.GetInitialDataInXml(employee, ms);
zipEntry.AddEntry("content.xml", ms);
zipEntry.Save(stream); //process sleep on this line
}
}
})
};
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = "FromPC.zip"
};
result.Content.Headers.ContentType =
new MediaTypeHeaderValue("application/octet-stream");
return result;
したい
1) _xmlRepository.GetInitialDataInXml からデータを取得する
2) Ionic.Zip を介してオンザフライでデータを圧縮する
3) WebApi アクションの出力として圧縮されたストリームを返す
しかし、この行では zipEntry.Save(stream); 実行プロセスが停止し、次の行に移動しません。メソッドは何も返さない
では、なぜファイルが返されないのでしょうか。