Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

<p align="center">English | <a href="./README.zh-CN.md">简体中文</a></p>


## Highlights

- Supports Ajax uploads with progress, headers, credentials, and custom request overrides.
Expand Down Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

<p align="center"><a href="./README.md">English</a> | 简体中文</p>


## 特性

- 支持带进度、请求头、凭证和自定义请求覆盖的 Ajax 上传。
Expand Down Expand Up @@ -98,9 +97,10 @@ npm start

### 方法

| 名称 | 类型 | 说明 |
| ------- | ------------------------- | ----------------------- |
| `abort` | `(file: RcFile) => void` | 中止进行中的上传。 |
| 名称 | 类型 | 说明 |
| ------------- | ------------------------ | -------------------- |
| `abort` | `(file: RcFile) => void` | 中止进行中的上传。 |
| `retryUpload` | `(file: RcFile) => void` | 重试特定文件的上传。 |

## 本地开发

Expand Down
8 changes: 8 additions & 0 deletions src/AjaxUploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,14 @@ class AjaxUploader extends Component<UploadProps> {
this.reqs[uid] = request(requestOption, { defaultRequest });
}

retryUpload = (originFile: RcFile) => {
Comment thread
EmilyyyLiu marked this conversation as resolved.
this.processFile(originFile, [originFile]).then(fileInfo => {
if (fileInfo.parsedFile !== null) {
this.post(fileInfo);
}
});
};
Comment thread
coderabbitai[bot] marked this conversation as resolved.

reset() {
this.setState({
uid: getUid(),
Expand Down
4 changes: 4 additions & 0 deletions src/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class Upload extends Component<UploadProps> {
this.uploader.abort(file);
}

retryUpload(file: RcFile) {
this.uploader.retryUpload(file);
}

saveUploader = (node: AjaxUpload) => {
this.uploader = node;
};
Expand Down
23 changes: 23 additions & 0 deletions tests/uploader.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,29 @@ describe('uploader', () => {
}, 100);
});

it('retryUpload should make new request', done => {
const uploadRef = React.createRef<any>();
render(<Upload ref={uploadRef} action="/test" />);

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);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

setTimeout(() => {
expect(requests.length).toBe(initialRequestCount + 1);
done();
}, 100);
});

it('drag to upload', done => {
const input = uploader.container.querySelector('input')!;

Expand Down
Loading