progress of file upload is added

This commit is contained in:
병준 박 2019-10-29 18:17:16 +09:00
parent 9ae1ed25c4
commit a880e89ba4

View File

@ -1,5 +1,11 @@
import { Injectable, Inject } from '@angular/core'; 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 { Observable } from 'rxjs';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
@ -109,18 +115,23 @@ export class CommonApiService {
public fileTalkSave( public fileTalkSave(
req: FileTalkSaveRequest, req: FileTalkSaveRequest,
fileTalkSaveUrl?: string fileTalkSaveUrl?: string
): Observable<FileTalkSaveResponse> { ): Observable<FileTalkSaveResponse | HttpProgressEvent> {
return this.httpClient const httpReq = new HttpRequest(
.post<any>( 'POST',
!!fileTalkSaveUrl !!fileTalkSaveUrl ? fileTalkSaveUrl : this.moduleConfig.urls.fileTalkSave,
? fileTalkSaveUrl encodeFileTalkSave(req),
: this.moduleConfig.urls.fileTalkSave, { reportProgress: true }
{}, );
{
params: encodeFileTalkSave(req) 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( public fileTalkShare(