From a880e89ba450083a53b7c6bcfd18118e851264d6 Mon Sep 17 00:00:00 2001 From: Richard Park Date: Tue, 29 Oct 2019 18:17:16 +0900 Subject: [PATCH] progress of file upload is added --- .../src/lib/services/common-api.service.ts | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/projects/ucap-webmessenger-api-common/src/lib/services/common-api.service.ts b/projects/ucap-webmessenger-api-common/src/lib/services/common-api.service.ts index 6d0b0e29..327735f8 100644 --- a/projects/ucap-webmessenger-api-common/src/lib/services/common-api.service.ts +++ b/projects/ucap-webmessenger-api-common/src/lib/services/common-api.service.ts @@ -1,5 +1,11 @@ import { Injectable, Inject } from '@angular/core'; -import { HttpClient } from '@angular/common/http'; +import { + HttpClient, + HttpEventType, + HttpResponse, + HttpRequest, + HttpProgressEvent +} from '@angular/common/http'; import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; @@ -109,18 +115,23 @@ export class CommonApiService { public fileTalkSave( req: FileTalkSaveRequest, fileTalkSaveUrl?: string - ): Observable { - return this.httpClient - .post( - !!fileTalkSaveUrl - ? fileTalkSaveUrl - : this.moduleConfig.urls.fileTalkSave, - {}, - { - params: encodeFileTalkSave(req) + ): Observable { + const httpReq = new HttpRequest( + 'POST', + !!fileTalkSaveUrl ? fileTalkSaveUrl : this.moduleConfig.urls.fileTalkSave, + encodeFileTalkSave(req), + { reportProgress: true } + ); + + return this.httpClient.request(httpReq).pipe( + map(event => { + if (event instanceof HttpResponse) { + return decodeFileTalkSave(event); + } else if (HttpEventType.UploadProgress === event.type) { + return event; } - ) - .pipe(map(res => decodeFileTalkSave(res))); + }) + ); } public fileTalkShare(