Skip to content

Commit b82d2f3

Browse files
fix(module:upload): fix the problem that the transformed file is lost (#7206)
1 parent e92b4d4 commit b82d2f3

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

components/upload/upload-btn.component.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
ViewEncapsulation
1818
} from '@angular/core';
1919
import { fromEvent, Observable, of, Subject, Subscription } from 'rxjs';
20-
import { map, switchMap, takeUntil } from 'rxjs/operators';
20+
import { map, switchMap, takeUntil, tap } from 'rxjs/operators';
2121

2222
import { warn } from 'ng-zorro-antd/core/logger';
2323
import { NzSafeAny } from 'ng-zorro-antd/core/types';
@@ -193,6 +193,7 @@ export class NzUploadBtnComponent implements OnInit, OnDestroy {
193193
return;
194194
}
195195
let process$: Observable<string | Blob | File | NzUploadFile> = of(file);
196+
let transformedFile: string | Blob | File | NzUploadFile | undefined;
196197
const opt = this.options;
197198
const { uid } = file;
198199
const { action, data, headers, transformFile } = opt;
@@ -238,7 +239,8 @@ export class NzUploadBtnComponent implements OnInit, OnDestroy {
238239
if (typeof transformFile === 'function') {
239240
const transformResult = transformFile(file);
240241
process$ = process$.pipe(
241-
switchMap(() => (transformResult instanceof Observable ? transformResult : of(transformResult)))
242+
switchMap(() => (transformResult instanceof Observable ? transformResult : of(transformResult))),
243+
tap(newFile => (transformedFile = newFile))
242244
);
243245
}
244246

@@ -249,7 +251,7 @@ export class NzUploadBtnComponent implements OnInit, OnDestroy {
249251
switchMap(() => dataResult),
250252
map(res => {
251253
args.data = res;
252-
return file;
254+
return transformedFile ?? file;
253255
})
254256
);
255257
} else {
@@ -264,7 +266,7 @@ export class NzUploadBtnComponent implements OnInit, OnDestroy {
264266
switchMap(() => headersResult),
265267
map(res => {
266268
args.headers = res;
267-
return file;
269+
return transformedFile ?? file;
268270
})
269271
);
270272
} else {

0 commit comments

Comments
 (0)