import { Component, Injector, ViewChild, ViewEncapsulation } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { AppConsts } from '@shared/AppConsts'; import {Location} from '@angular/common'; import { Router } from '@angular/router'; import { appModuleAnimation } from '@shared/animations/routerTransition'; import { AppComponentBase } from '@shared/common/app-component-base'; import { EntityDtoOfInt64, DriversServiceProxy, UserListDto, GetDriverDetailsDto, VendorsServiceProxy,OrderStatusAttachmentServiceProxy } from '@shared/service-proxies/service-proxies'; import { FileDownloadService } from '@shared/utils/file-download.service'; import { Observable } from 'rxjs'; import { HttpEventType, HttpClient } from '@angular/common/http'; import { map } from "rxjs/operators"; import { saveAs } from 'file-saver'; @Component({ encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()], template: '', }) export class ImageUrlComponent extends AppComponentBase { id: any; constructor( injector: Injector, private route: ActivatedRoute, private image:OrderStatusAttachmentServiceProxy, private location:Location, private _fileDownloadService: FileDownloadService, private _httpClient: HttpClient ) { super(injector); } ngOnInit(){ this.route.paramMap.subscribe(params => { this.id = params.get("id"); this.image.getImageLink(this.id).subscribe( response => { this.DownloadFile(response.content) .subscribe( success => { saveAs(success, response.fileName); window.location.href="/app/sprintship/dispatch"; }, err => { alert("Server error while downloading file."); } ); }) }); } DownloadFile( content:string ): Observable { return this._httpClient.get('data:image/jpeg;base64,' + content, { responseType: 'blob', observe: 'response' }).pipe( map((res: any) => { return new Blob([res.body], { type: 'image/jpeg' }); }) ); } }