Web APIメソッドを呼び出して、ユーザーがメモリに作成したzipファイルをダウンロードできるようにします。私はまた、メモリにもエントリを作成したい。ダウンロードzipArchive from c#web apiメソッドは、 "net :: ERR_CONNECTION_RESET"をクロムで返します。
サーバーにダウンロードを正しく出力させるのに問題があります。ここで
は、私のWeb APIメソッドである:ここで
[HttpGet]
[Route("api/downloadstaffdata")]
public HttpResponseMessage DownloadStaffData()
{
var response = new HttpResponseMessage(HttpStatusCode.OK);
using (var stream = new MemoryStream())
{
using (var archive = new ZipArchive(stream, ZipArchiveMode.Create, true))
{
//future for loop to create entries in memory from staff list
var entry = archive.CreateEntry("bob.txt");
using (var writer = new StreamWriter(entry.Open()))
{
writer.WriteLine("Info for: Bob");
}
//future add staff images as well
}
stream.Seek(0, SeekOrigin.Begin);
response.Content = new StreamContent(stream);
}
response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
{
FileName = "staff_1234_1.zip"
};
response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/zip");
return response;
}
は私の呼び出しjsのコードです:ここでは
window.open('api/downloadstaffdata');
は、Chromeからの応答です:
net::ERR_CONNECTION_RESET
Iドン私が間違っていることを知りません。私はすでにSOを検索し、zipファイルの作成に関する記事を読んでいますが、クライアントにzipアーカイブを返そうとしているときに接続リセットのエラーを渡すことはできません。
アイデア?
P.S.大きなzipファイルを作成するために必要な時間のためにシステムが応答しないという問題が発生している場合は、これを試してください。[StackOverflow:HttpContext出力ストリームを使用してZipArchiveに書き込む](http://stackoverflow.com/questions/16585488/ ziparchive-using-the-httpcontext-outputstreamを使用して) – ShuberFu
まあまあ、なぜ私はそれを考えなかった!ありがとう – Nate