import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { throwError } from 'rxjs'; import { ConfigService } from '@arrow/bom/config'; import { MessageBusService } from './message-bus/message-bus.service'; import { catchError } from 'rxjs/operators'; @Injectable() export class UploadService { defaultErrorMessage = 'Server error'; constructor( private http: HttpClient, private config: ConfigService, private _messageBus: MessageBusService ) {} uploadFile(file: any) { const form = new FormData(); form.append('file', file, file.name); const headers = new HttpHeaders({ Accept: 'multipart/form-data' }); const options = { headers: headers, withCredentials: true }; //const url = `${this.config.apiUrl}/process`; //.Net Framework const url = `${this.config.apiCoreUrl}/api/ProcessedFile`; //.Net Core return this.http .post( url, form, options ); } private handleError(error: any): any { this._messageBus.to('ch:loader', { payload: true }); return throwError(error || this.defaultErrorMessage); } }