1

I send a zipfile as a response.Content:

[HttpGet]
[Route("Package")]
public async Task<HttpResponseMessage> GetLogsPackage()
{
   HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);                     
   using (var stream = new MemoryStream())
   {
       using (var zipFile = ZipFile.Read((Path.Combine(path, opId.ToString()) + ".zip")))                
       {
           zipFile.Save(stream);
           response.Content = new StreamContent(stream);
           response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
           response.Content.Headers.ContentLength = stream.Length;
       }
   }
   return response;
}

how to get this stream after call to this method? My code doesn't work( can't read as zipfile) I send stream.lenght ,for example, 345673, but receive response with 367 lenght. What is wrong?

  var response = await _coreEndpoint.GetLogsPackage();
  using (var stream = response.Content.ReadAsStreamAsync())
  using (var zipFile = ZipFile.Read(stream))
   {   //do something with zip-file
IronAces
  • 1,857
  • 1
  • 27
  • 36
Lizabeth
  • 11
  • 3

1 Answers1

0

Looks like you should be await'ing ReadAsStreamAsync:

using (var stream = await response.Content.ReadAsStreamAsync())

Currently your code is passing a Task<Stream> to ZipFile.Read, which is probably not what you intend.

easuter
  • 1,167
  • 14
  • 20