title: How to correctly download files to Angular from ASP.NET Core?
body: <p>I have a file on the server that I want to send to the client:</p>
  
  <pre><code>[HttpPost]
  public IActionResult Test()
  {
      byte[] bytes = System.IO.File.ReadAllBytes(Path.Combine(FilesFolder, "test.docx"));
      return File(bytes, _contentTypeWord);
  }
  </code></pre>
  
  <p>I also tried with</p>
  
  <pre><code>return PhysicalFile(pathUploadFile, "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
  </code></pre>
  
  <p>At the client I accept using:</p>
  
  <pre><code>private _downloadFile(data: ArrayBuffer, fileName: string, contentType: string) {
      var blob = new Blob([data], { type: contentType });
      var url = window.URL.createObjectURL(blob);
  
      var link = document.createElement("a");
      link.setAttribute("href", url);
      link.setAttribute("download", fileName);
      link.style.display = "none";
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link);
  }
  
  public test() {
      this.http.post("Diplom/Test", { }, {
          headers: this.headers(),
      }).subscribe(
          result =&gt; {
              this._downloadFile(result.arrayBuffer(), "test.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
          },
          error =&gt; {
              alert("Не удалось отредактировать файл");
              console.error(JSON.stringify(error));
          })
  }
  </code></pre>
  
  <p>The file that the client receives is corrupt and does not open. The file that is on the server is fine and opens perfectly. The resulting file still does not open, and even weighs 2 times more (on the server 487 KB, and the client has 925 KB). </p>