I have experience in C# backend and ASP.Net MVC. Now I am making my first attempt on Angular 2. It takes time but I like most of it. Now I am stuck on a simple file download.
I have read all examples that i found here on Stackoverflow, but I still don't get my example to work.
On server side I have this C# code:
public ActionResult DownloadPicture(long id) { var bytes = System.IO.File.ReadAllBytes("images\dummy.jpg"); return GetAttachement(bytes, "DummyFile.jpg"); } private ActionResult GetAttachement(byte[] bytes, string fileName) { var contentType = MimeMapping.GetMimeMapping(fileName); var contentDisposition = new System.Net.Mime.ContentDisposition { FileName = fileName, Inline = true }; Response.AppendHeader("Content-Disposition", contentDisposition.ToString()); return File(bytes, contentType); } On client side I have this Typescript code:
public pictureDownload(id: number): void { let options = new RequestOptions({ search: new URLSearchParams("id=" + id) }); this.http.get(this.urlPictureDownload, options).subscribe((data: any) => { // var blob = new Blob([data._body], { type: "image/jpeg" }); // var url = window.URL.createObjectURL(blob); // window.open(url); }); } The request is coming in to server side. The array is downloaded. I guess my problem lies on client side. Can anyone help me out?
arraybuffer. Hth...