如何解决AngularJS $get 为移动设备上的文件名添加 .html 扩展名
$http.get(URL,{responseType: 'blob'})
.then(function(file) {
File.open(file,fileName) // filename = something.jpg
})
var open = function (fileContent,fileName,format) {
if(fileContent.headers != undefined){
var headers = fileContent.headers()
var contentType = headers['content-type'];
var linkElement = document.createElement('a');
try {
var blob = new Blob([fileContent.data],{ type: contentType });
var url = window.URL.createObjectURL(blob);
linkElement.setAttribute('href',url);
linkElement.setAttribute("download",fileName);
var clickEvent = new MouseEvent("click",{
"view": window,"bubbles": true,"cancelable": false
});
linkElement.dispatchEvent(clickEvent);
} catch (ex) {
console.error(ex);
}
} else {
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
var blob = textToBlob(fileContent),url = window.URL.createObjectURL(blob);
a.href = url;
a.download = fileName;
if(format != undefined){
a.download = fileName + '.' + format;
}
a.click();
window.URL.revokeObjectURL(url)
}
}
在桌面浏览器中,它可以毫无问题地下载文件。但是,一旦我在移动设备上尝试它(不是“在 chrome 中显示为移动设备”),该文件的文件名就会增加一个 .html
。我怎样才能防止这种情况发生?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。