I am trying to download word document, it is working but i am not how to set file name. Every time it is downloading with some unique name.
this.downloadData("downloadVehicleLine").subscribe(
data => {
this.downLoadFile(data);
})
downLoadFile(data: any) {
var blob = new Blob([data], { type: 'application/octet-stream' });
var url = window.URL.createObjectURL(blob);
var pwa = window.open(url, "createdocument.docx");
if (!pwa || pwa.closed || typeof pwa.closed == 'undefined') {
alert('Please disable your Pop-up blocker and try again.');
}
}
It should download word document with the name createdocument.docx
I am trying to download word document, it is working but i am not how to set file name. Every time it is downloading with some unique name.
this.downloadData("downloadVehicleLine").subscribe(
data => {
this.downLoadFile(data);
})
downLoadFile(data: any) {
var blob = new Blob([data], { type: 'application/octet-stream' });
var url = window.URL.createObjectURL(blob);
var pwa = window.open(url, "createdocument.docx");
if (!pwa || pwa.closed || typeof pwa.closed == 'undefined') {
alert('Please disable your Pop-up blocker and try again.');
}
}
It should download word document with the name createdocument.docx
Share Improve this question edited Dec 26, 2019 at 8:43 Nimer Awad 4,2093 gold badges19 silver badges34 bronze badges asked Jan 29, 2019 at 7:59 Vikash AnandVikash Anand 671 gold badge5 silver badges11 bronze badges1 Answer
Reset to default 5I think you can use an anchor element reference instead of window.URL
; because you can set the name of the file to download
property of the element.
You can use this code to download files:
var blob = new Blob([data], { type: 'application/octet-stream' });
var link = document.createElement('a');
link.href = URL.createObjectURL(blob);
// set the name of the file
link.download = "createdocument.docx";
// clicking the anchor element will download the file
link.click();
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744169384a4561459.html
评论列表(0条)