Skip to content
Snippets Groups Projects

Resolve "Télécharger une archive"

Merged François Agneray requested to merge 23-telecharger-une-archive into develop
54 files
+ 2075
244
Compare changes
  • Side-by-side
  • Inline
Files
54
@@ -7,8 +7,7 @@
* file that was distributed with this source code.
*/
import { Component, Input, ChangeDetectionStrategy } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy } from '@angular/core';
import { DownloadRendererConfig } from 'src/app/metamodel/models/renderers/download-renderer-config.model';
import { getHost } from 'src/app/shared/utils';
@@ -28,8 +27,9 @@ export class DownloadRendererComponent {
@Input() datasetName: string;
@Input() datasetPublic: boolean;
@Input() config: DownloadRendererConfig;
@Output() downloadFile: EventEmitter<{url: string, fileId: string, datasetName: string, filename: string}> = new EventEmitter();
constructor(private appConfig: AppConfigService, private http: HttpClient) { }
constructor(private appConfig: AppConfigService) { }
/**
* Returns link href.
@@ -50,21 +50,23 @@ export class DownloadRendererComponent {
}
/**
* Downloads file on click.
* Starts downloading file on click.
*/
click(event): void {
event.preventDefault();
const url = this.getHref();
const filename = url.substring(url.lastIndexOf('/') + 1);
const href = this.getHref();
this.http.get(href, { responseType: "blob" }).subscribe(
data => {
const filename = href.substring(href.lastIndexOf('/') + 1);
const n = Math.floor(Math.random() * 11);
const k = Math.floor(Math.random() * 1000000);
const m = String.fromCharCode(n) + k;
let downloadLink = document.createElement('a');
downloadLink.href = window.URL.createObjectURL(data);
downloadLink.setAttribute('download', filename);
downloadLink.click();
}
);
this.downloadFile.emit({
url,
fileId: m,
datasetName: this.datasetName,
filename
});
}
}
Loading