Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async downloadFile(file: UploadedFileMetaData) {
- if (this.downloading.has(file)) {
- return;
- }
- this.downloading.add(file);
- let url: string;
- try {
- url = await this.blobStorageService.getDownloadUrl(file);
- } catch (err) {
- throw err;
- }
- return this.http
- .get(url, {
- responseType: ResponseContentType.Blob
- })
- .map((res) => {
- return {
- filename: file.blobName,
- data: res.blob()
- };
- })
- .subscribe(
- (res) => {
- console.log('start download:', res);
- const fileUrl = window.URL.createObjectURL(res.data);
- const a = document.createElement('a');
- document.body.appendChild(a);
- a.setAttribute('style', 'display: none');
- a.href = fileUrl;
- a.download = res.filename;
- a.click();
- window.URL.revokeObjectURL(fileUrl);
- a.remove();
- },
- (error) => {
- this.downloading.delete(file);
- console.log('download error:', JSON.stringify(error));
- },
- () => {
- this.downloading.delete(file);
- console.log('Completed file download.');
- }
- );
- }
Add Comment
Please, Sign In to add comment