简体   繁体   中英

How to change file name when download it from server in AngularJS

I download a file using below code in AngularJS

 $scope.download = function (row) {
        var url = row.entity.downloadUrl;
        window.open(url, "_blank");
 };

The url is an image from file serve.How could I change/set the file name when I download it without using the name from file server.

I do not want to use any plugin,is that possible?

Create a a html attribute and use that to download your file.

var file_path = 'row.entity.downloadUrl';
var a = document.createElement('A');
a.href = file_path;
a.download = 'you new file name';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM