Direct Download File

5 views
Skip to first unread message

Adnan Salahuddin

unread,
Sep 19, 2017, 5:06:17 AM9/19/17
to Angular and AngularJS discussion
Hi Folks,

I am using Asp.net Core and Angular 2/4

In Asp.net:
[HttpGet("GetDownload/{id}")]
public FileResult Download([FromRoute] int id)
{
   
var getFile = _context.UploadPoliceReports.FirstOrDefault(m => m.UploadPoliceReportID == id);
   
MemoryStream ms = new MemoryStream(getFile.Data);
   
return File(ms, getFile.ContentType, getFile.FileName);
}



Well, I run "http://localhost:5001/...../getDownloadPolice/43" to a direct download image file and seem GOOD!

Now...
In Service:
getDownloadPolice(id: number) {
   
   
//return this.http.get(this.downloadPoliceUrl + '/' + id, { responseType: ResponseContentType.Blob })

     
return this.http.get(this.downloadPoliceUrl + '/' + id)
       
.map((data: Response) => {
             
<<<??????>>>
           
//return data;
           
//return new Blob([data.blob()], { type: data.blob().type });
       
})
       
.do(data => console.log(data));
}



In Component:
getDownload() {
   
this.userFormVehicleService.getDownloadPolice(43).subscribe(data => {
   
<<<??????>>>
   
});
}



I have no idea what i should write down the code in Service and Component.
Any Idea?
I am waiting for your response.

Thanks in Advance
Reply all
Reply to author
Forward
0 new messages