If I enter the URL (http://localhost:13225/hellozip) in a browser the file is download in the usual way.
However if I navigate to the swagger ui and “Try it now” the response is a blob of text instead of downloading the file. Can you point out what I’m doing incorrectly. Thanks
[Route("/hellozip")]
public class HelloZip { }
public object Get(HelloZip request)
{
string tempPath = Path.GetTempPath();
string filePath = Path.Combine(tempPath, "HelloTest.zip");
base.Response.ContentType = "application/zip";
using (MemoryStream memoryStream = new MemoryStream())
{
using (var zipArchive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
{
ZipArchiveEntry zipArchiveEntry = zipArchive.CreateEntry("Foo.txt");
using (Stream stream = zipArchiveEntry.Open())
{
using (StreamWriter streamWriter = new StreamWriter(stream))
{
streamWriter.Write("Bar!");
}
}
}
using (var fileStream = new FileStream(filePath, FileMode.Create))
{
memoryStream.Seek(0, SeekOrigin.Begin);
memoryStream.CopyTo(fileStream);
}
}
return new HttpResult(new FileInfo(filePath), true);
}