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 { 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<FileTalkSaveResponse> {
return this.httpClient
.post<any>(
!!fileTalkSaveUrl
? fileTalkSaveUrl
: this.moduleConfig.urls.fileTalkSave,
{},
{
params: encodeFileTalkSave(req)
): Observable<FileTalkSaveResponse | HttpProgressEvent> {
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(