From 33a1d04deab9615f01f59e2ce7af6667a9e1d573 Mon Sep 17 00:00:00 2001 From: lh01217311 Date: Mon, 27 Jul 2026 17:38:12 +0800 Subject: [PATCH 1/3] feat: add retryUpload method for upload - Add retryUpload method to AjaxUploader - Add retryUpload method to Upload component - Add unit test for retryUpload - Update README docs Co-Authored-By: Claude --- README.md | 8 ++++---- README.zh-CN.md | 8 ++++---- src/AjaxUploader.tsx | 8 ++++++++ src/Upload.tsx | 4 ++++ tests/uploader.spec.tsx | 23 +++++++++++++++++++++++ 5 files changed, 43 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 440e9659..a40f79a7 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,6 @@

English | 简体中文

- ## Highlights - Supports Ajax uploads with progress, headers, credentials, and custom request overrides. @@ -98,9 +97,10 @@ Then open `http://localhost:8000`. ### Methods -| Name | Type | Description | -| ------- | ------------------------- | ----------------------- | -| `abort` | `(file: RcFile) => void` | Abort an active upload. | +| Name | Type | Description | +| ------------- | ------------------------ | ------------------------------------ | +| `abort` | `(file: RcFile) => void` | Abort an active upload. | +| `retryUpload` | `(file: RcFile) => void` | Retry an upload for a specific file. | ## Development diff --git a/README.zh-CN.md b/README.zh-CN.md index cc0e8dc8..04e23474 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -15,7 +15,6 @@

English | 简体中文

- ## 特性 - 支持带进度、请求头、凭证和自定义请求覆盖的 Ajax 上传。 @@ -98,9 +97,10 @@ npm start ### 方法 -| 名称 | 类型 | 说明 | -| ------- | ------------------------- | ----------------------- | -| `abort` | `(file: RcFile) => void` | 中止进行中的上传。 | +| 名称 | 类型 | 说明 | +| ------------- | ------------------------ | -------------------- | +| `abort` | `(file: RcFile) => void` | 中止进行中的上传。 | +| `retryUpload` | `(file: RcFile) => void` | 重试特定文件的上传。 | ## 本地开发 diff --git a/src/AjaxUploader.tsx b/src/AjaxUploader.tsx index 0244c3be..d90532a8 100644 --- a/src/AjaxUploader.tsx +++ b/src/AjaxUploader.tsx @@ -301,6 +301,14 @@ class AjaxUploader extends Component { this.reqs[uid] = request(requestOption, { defaultRequest }); } + retryUpload = (originFile: RcFile) => { + this.processFile(originFile, [originFile]).then(fileInfo => { + if (fileInfo.parsedFile !== null) { + this.post(fileInfo); + } + }); + }; + reset() { this.setState({ uid: getUid(), diff --git a/src/Upload.tsx b/src/Upload.tsx index 23541e31..6fe755ec 100644 --- a/src/Upload.tsx +++ b/src/Upload.tsx @@ -30,6 +30,10 @@ class Upload extends Component { this.uploader.abort(file); } + retryUpload(file: RcFile) { + this.uploader.retryUpload(file); + } + saveUploader = (node: AjaxUpload) => { this.uploader = node; }; diff --git a/tests/uploader.spec.tsx b/tests/uploader.spec.tsx index ef835041..172ee3fe 100644 --- a/tests/uploader.spec.tsx +++ b/tests/uploader.spec.tsx @@ -253,6 +253,29 @@ describe('uploader', () => { }, 100); }); + it('retryUpload should make new request', done => { + const uploadRef = React.createRef(); + render(); + + const file = { + name: 'retry.png', + toString() { + return this.name; + }, + }; + const files = [file]; + (files as any).item = (i: number) => files[i]; + + const initialRequestCount = requests.length; + + uploadRef.current.retryUpload(file as any); + + setTimeout(() => { + expect(requests.length).toBe(initialRequestCount + 1); + done(); + }, 100); + }); + it('drag to upload', done => { const input = uploader.container.querySelector('input')!; From 5f6c5c1e94cb0b33355e5cf188533a13f02008ac Mon Sep 17 00:00:00 2001 From: lh01217311 Date: Mon, 24 Aug 2026 14:50:57 +0800 Subject: [PATCH 2/3] fix: handle processFile rejection and improve test fixture --- src/AjaxUploader.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/AjaxUploader.tsx b/src/AjaxUploader.tsx index d90532a8..349a75d0 100644 --- a/src/AjaxUploader.tsx +++ b/src/AjaxUploader.tsx @@ -302,11 +302,13 @@ class AjaxUploader extends Component { } retryUpload = (originFile: RcFile) => { - this.processFile(originFile, [originFile]).then(fileInfo => { - if (fileInfo.parsedFile !== null) { - this.post(fileInfo); - } - }); + this.processFile(originFile, [originFile]) + .then(fileInfo => { + if (fileInfo.parsedFile) { + this.post(fileInfo); + } + }) + .catch(() => {}); }; reset() { From 6082a3e723ed98a83d88fa1dd3f559df59fac2eb Mon Sep 17 00:00:00 2001 From: lh01217311 Date: Mon, 24 Aug 2026 15:16:09 +0800 Subject: [PATCH 3/3] test: cover retryUpload when action rejects Co-Authored-By: Claude --- tests/uploader.spec.tsx | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/uploader.spec.tsx b/tests/uploader.spec.tsx index 172ee3fe..e73ec873 100644 --- a/tests/uploader.spec.tsx +++ b/tests/uploader.spec.tsx @@ -276,6 +276,34 @@ describe('uploader', () => { }, 100); }); + it('retryUpload should not make request when action rejects', done => { + const uploadRef = React.createRef(); + render( + { + throw new Error('action error'); + }} + />, + ); + + const file = { + name: 'reject.png', + toString() { + return this.name; + }, + }; + + const initialRequestCount = requests.length; + + uploadRef.current.retryUpload(file as any); + + setTimeout(() => { + expect(requests.length).toBe(initialRequestCount); + done(); + }, 100); + }); + it('drag to upload', done => { const input = uploader.container.querySelector('input')!;