Skip to content

Commit fd3346f

Browse files
authored
Merge pull request react-component#53 from edgji/custom-request
add custom request option
2 parents dbf0735 + 744a778 commit fd3346f

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ React.render(<Upload />, container);
7070
|onSuccess | function | | success callback |
7171
|onProgress | function || progress callback, only for modern browsers|
7272
|beforeUpload| function |null| before upload check, return false or a rejected Promise will stop upload, only for modern browsers|
73+
|customRequest | function | null | provide an override for the default xhr behavior for additional customization|
7374
|withCredentials | boolean | false | ajax upload with cookie send |
7475

7576
#### onError arguments
@@ -84,6 +85,23 @@ React.render(<Upload />, container);
8485
2. `file`: upload file
8586

8687

88+
### customRequest
89+
90+
Allows for advanced customization by overriding default behavior in AjaxUplaoder. Provide your own XMLHttpRequest calls to interface with custom backend processes or interact with AWS S3 service through the aws-sdk-js package.
91+
92+
customRequest callback is passed an object with:
93+
94+
* `onProgress: (event: { percent: number }): void`
95+
* `onError: (event: Error, body?: Object): void`
96+
* `onSuccess: (body: Object): void`
97+
* `data: Object`
98+
* `filename: String`
99+
* `file: File`
100+
* `withCredentials: Boolean`
101+
* `action: String`
102+
* `headers: Object`
103+
104+
87105
### methods
88106

89107
abort(file?: File) => void: abort the uploading file

src/AjaxUploader.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import React, { PropTypes } from 'react';
44
import classNames from 'classnames';
5-
import request from './request';
5+
import defaultRequest from './request';
66
import getUid from './uid';
77

88
const AjaxUploader = React.createClass({
@@ -22,6 +22,7 @@ const AjaxUploader = React.createClass({
2222
]),
2323
headers: PropTypes.object,
2424
beforeUpload: PropTypes.func,
25+
customRequest: PropTypes.func,
2526
withCredentials: PropTypes.bool,
2627
},
2728

@@ -111,6 +112,7 @@ const AjaxUploader = React.createClass({
111112
data = data(file);
112113
}
113114
const { uid } = file;
115+
const request = props.customRequest || defaultRequest;
114116
this.reqs[uid] = request({
115117
action: props.action,
116118
filename: props.name,

src/Upload.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const Upload = React.createClass({
2626
multiple: PropTypes.bool,
2727
disabled: PropTypes.bool,
2828
beforeUpload: PropTypes.func,
29+
customRequest: PropTypes.func,
2930
onReady: PropTypes.func,
3031
withCredentials: PropTypes.bool,
3132
supportServerRender: PropTypes.bool,
@@ -47,6 +48,7 @@ const Upload = React.createClass({
4748
supportServerRender: false,
4849
multiple: false,
4950
beforeUpload: null,
51+
customRequest: null,
5052
withCredentials: false,
5153
};
5254
},

0 commit comments

Comments
 (0)