10 examples of 'angular download file on click' in JavaScript

Every line of 'angular download file on click' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
15function download (file) {
16 const mime = file.type || 'text/plain';
17 const type = `${mime};charset=utf-8`;
18 const filename = file.name || 'download.txt';
19
20 const blob = new Blob([file.content], {type});
21 saveAs(blob, filename); // shim this
22}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

164private onDownload(e: Event) {
165 e.preventDefault();
166 this.selector.close();
167
168 this._fileService.download(this.model.file_info);
169}
40function startDownload(path, fileName) {
41 var anchor = $("#DownloadAnchor");
42 anchor.attr("target", "_self");
43 anchor.attr("href", path);
44 anchor.attr("download", fileName);
45 anchor[0].click();
46};
477onDownloadFile (filename, href) {
478
479 let a = document.createElement('a')
480
481 a.download = filename
482 a.href = href
483
484 a.click()
485}
22download() {
23 var fileName = this.imageService.fileName;
24 this.embedService.embeddedCanvas.toBlob(function (blob) {
25 download(blob, fileName, 'image/png');
26 })
27}
42_triggerDownload () {
43 const archive = this.context.archive
44 const node = this._getNode()
45 const isLocal = this._isLocal()
46 let url = node.href
47 if (isLocal) {
48 url = archive.getDownloadLink(node.href)
49 }
50 if (url) {
51 this.refs.link.el.attr({
52 'href': url
53 })
54 this.refs.link.el.click()
55 }
56}
86export function download(url = "", showLoading = true) {
87 if (showLoading) wx.showLoading({title: '加载中',});
88 return new Promise((resolve, reject) => {
89 wx.downloadFile({
90 url: url,
91 success(res) {
92 resolve(res.tempFilePath);
93 },
94 fail(res){
95 reject(res);
96 },
97 complete(){
98 if (showLoading) wx.hideLoading();
99 }
100 })
101
102 });
103}
18downloadFile() {
19 console.log("Loading data...");
20 this.primeService.downloadFile((data) => {
21 var file = data.fileBase64;
22 console.log(file);
23 });
24}
45function download() {
46 var url = $("input").text
47 $ui.toast("开始下载: " + url)
48 $ui.loading(true)
49 $http.download({
50 url: url,
51 handler: function(resp) {
52 $ui.loading(false)
53 $share.sheet(resp.data)
54 }
55 })
56}
346downloadItem() {
347 const file = this.selectedItems.firstObject as unknown as File;
348 // TODO: Make this a link that looks like a button
349 window.location.href = getHref(file.links.download!);
350 if (!this.canEdit) {
351 this.analytics.click('button', 'Quick Files - Download');
352 }
353}

Related snippets