Skip to content

Commit

Permalink
fix(module:upload): fix the problem that the transformed file is lost (
Browse files Browse the repository at this point in the history
  • Loading branch information
HyperLife1119 committed Mar 3, 2022
1 parent e92b4d4 commit b82d2f3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions components/upload/upload-btn.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
ViewEncapsulation
} from '@angular/core';
import { fromEvent, Observable, of, Subject, Subscription } from 'rxjs';
import { map, switchMap, takeUntil } from 'rxjs/operators';
import { map, switchMap, takeUntil, tap } from 'rxjs/operators';

import { warn } from 'ng-zorro-antd/core/logger';
import { NzSafeAny } from 'ng-zorro-antd/core/types';
Expand Down Expand Up @@ -193,6 +193,7 @@ export class NzUploadBtnComponent implements OnInit, OnDestroy {
return;
}
let process$: Observable<string | Blob | File | NzUploadFile> = of(file);
let transformedFile: string | Blob | File | NzUploadFile | undefined;
const opt = this.options;
const { uid } = file;
const { action, data, headers, transformFile } = opt;
Expand Down Expand Up @@ -238,7 +239,8 @@ export class NzUploadBtnComponent implements OnInit, OnDestroy {
if (typeof transformFile === 'function') {
const transformResult = transformFile(file);
process$ = process$.pipe(
switchMap(() => (transformResult instanceof Observable ? transformResult : of(transformResult)))
switchMap(() => (transformResult instanceof Observable ? transformResult : of(transformResult))),
tap(newFile => (transformedFile = newFile))
);
}

Expand All @@ -249,7 +251,7 @@ export class NzUploadBtnComponent implements OnInit, OnDestroy {
switchMap(() => dataResult),
map(res => {
args.data = res;
return file;
return transformedFile ?? file;
})
);
} else {
Expand All @@ -264,7 +266,7 @@ export class NzUploadBtnComponent implements OnInit, OnDestroy {
switchMap(() => headersResult),
map(res => {
args.headers = res;
return file;
return transformedFile ?? file;
})
);
} else {
Expand Down

0 comments on commit b82d2f3

Please sign in to comment.