title: Downloading byte[] of generated pdf using nodeservices in Asp.net Core 1.1
body: <p>I'm trying to download a nodeServices generated pdf file that is in the form of byte array. here is my original code:</p>
  
  <pre><code>[HttpGet]
  [Route("[action]/{appId}")]
  public async Task&lt;IActionResult&gt; Pdf(Guid appId, [FromServices] INodeServices nodeServices)
  {
      // generateHtml(appId) is a function where my model is converted to html.
      // then nodeservices will generate the pdf for me as byte[].
      var result = await nodeServices.InvokeAsync&lt;byte[]&gt;("./pdf", 
              await generateHtml(appId));
      HttpContext.Response.ContentType = "application/pdf";
      HttpContext.Response.Headers.Add("x-filename", "myFile.pdf");
      HttpContext.Response.Headers.Add("Access-Control-Expose-Headers", "x-filename");
      HttpContext.Response.Body.Write(result, 0, result.Length);
      return new ContentResult();
  }
  </code></pre>
  
  <p>This code was working fine, it will show the pdf file in the browser, eg. chrome, and when I try to download it, I get "failed, network error".</p>
  
  <p>I've searched here and there, I saw some suggestions to return File instead:</p>
  
  <pre><code>return File(result, "application/pdf");
  </code></pre>
  
  <p>that didn't work either, another thing was adding "Content-Disposition" header: </p>
  
  <pre><code>HttpContext.Response.Headers.Add("Content-Disposition", string.Format("inline;filename={0}", "myFile.pdf"));
  </code></pre>
  
  <p>others suggested to use <code>FileStreamResult</code>, no good either.
  I realized that the problem could be about my generated file (byte[]) does not have a path or a link of his own, so I saved the bytes to my server, then got the file again by its path, then to memory stream, and finally return a file containing the memory stream:</p>
  
  <pre><code>var result = await nodeServices.InvokeAsync&lt;byte[]&gt;("./pdf", await generateHtml(appId));
  var tempfilepath = Path.Combine(_environment.WebRootPath, $"temp/{appId}.pdf");
  
  System.IO.File.WriteAllBytes(tempfilepath, result);
  
  var memory = new MemoryStream();
  using (var stream = new FileStream(tempfilepath, FileMode.Open))
  {
      await stream.CopyToAsync(memory);
  }
  memory.Position = 0;
  
  return File(memory, "application/pdf", Path.GetFileName(tempfilepath));
  </code></pre>
  
  <p>which worked! it showed the file in the browser, and I could download it, but, I did not want any files to be stored on my server, my question is, can't I just download the file without the need to store it?</p>