Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(module:upload): fix the problem that the transformed file is lost #7206

Merged
merged 1 commit into from Mar 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions components/upload/upload-btn.component.ts
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