在文件名中加上引号或使用encodeURIComponent()函数将文件名转换成URL编码。
例如,如果要下载名为"file with spaces.txt"的文件,可以将下载链接中的文件名改为""file with spaces.txt""或者使用如下代码中的encodeURIComponent()函数:
app.controller('myController', function($scope, $http) {
$scope.downloadFile = function(fileUrl, fileName) {
var link = document.createElement('a');
link.href = fileUrl;
link.target = '_blank';
link.download = encodeURIComponent(fileName); //转换成URL编码
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
};
});