加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angularjs简单文件下载

发布时间:2020-12-17 09:05:24 所属栏目:安全 来源:网络整理
导读:HTML: a href="mysite.com/uploads/asd4a4d5a.pdf" download="foo.pdf" 上传获得唯一的文件名,而真实名称保存在数据库中。我想实现一个简单的文件下载。但是上面的代码重定向到/因为: $routeProvider.otherwise({ redirectTo: '/',controller: MainContro
HTML:
<a href="mysite.com/uploads/asd4a4d5a.pdf" download="foo.pdf">

上传获得唯一的文件名,而真实名称保存在数据库中。我想实现一个简单的文件下载。但是上面的代码重定向到/因为:

$routeProvider.otherwise({
    redirectTo: '/',controller: MainController
});

我试过

$scope.download = function(resource){
    window.open(resource);
}

但这只是在一个新的窗口中打开文件。

任何想法如何启用任何文件类型的真正下载?

https://docs.angularjs.org/guide/$location#html-link-rewriting

In cases like the following,links are not rewritten; instead,the
browser will perform a full page reload to the original link.

  • Links that contain target element Example:
    <a href="/ext/link?a=b" target="_self">link</a>

  • Absolute links that go to a different domain Example:
    <a href="http://angularjs.org/">link</a>

  • Links starting with ‘/’ that lead to a different base path when base is defined Example:
    <a href="/not-my-base/link">link</a>

所以在你的情况下,你应该添加一个目标属性,如…

<a target="_self" href="example.com/uploads/asd4a4d5a.pdf" download="foo.pdf">

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读