Skip to content

Commit 9cb99ff

Browse files
committed
Added XMLHttpRequest withCredentials property #36
1 parent d453da4 commit 9cb99ff

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ A library that will make things easier within the React framework for galleries
8181
| `footer` | `Bolean` Or `Function` | `false` | `function({ images, accept, uploadFiles, openDialogue })` |
8282
| `rules` | `Object` | `null` | `size`,` limit`, `width`,` height` features can be limited. [Rules](#Rules) |
8383
| `customRequest` | `Function` | `null` | You can customize the http request in your own way. [CustomRequest](#CustomRequest) |
84+
| `withCredentials` | `Boolean` | `false` | [XMLHttpRequest.withCredentials](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials) |
8485
| `source` | `Function` | `null` | Enter the url of the photo from the returned answer. `(response) => response.url` |
8586
| `alias` | `Function` | `null` | Can include the data of the image to be loaded in the object and change its name. `(response) => ({ id: response.imageID, slug: response.slug })` |
8687
| `onSuccess` | `Function` | `empty` | Return for uploaded image. `function(image)` |

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-upload-gallery",
3-
"version": "0.4.0",
3+
"version": "0.4.1",
44
"license": "MIT",
55
"author": "Muhammet INAN",
66
"repository": {

src/PropTypes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const defaultProps = {
2727
rules: null,
2828

2929
customRequest: null,
30+
withCredentials: false,
3031
source: null,
3132
alias: null,
3233

@@ -84,6 +85,7 @@ export const propTypes = {
8485
}),
8586

8687
customRequest: PropTypes.func,
88+
withCredentials: PropTypes.bool,
8789
source: PropTypes.func,
8890
alias: PropTypes.func,
8991

src/RUG.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,13 @@ class RUG extends React.Component {
362362
}
363363

364364
upload({ uid, file, data }, finish) {
365-
const { send, action, headers, customRequest } = this.props;
365+
const {
366+
send,
367+
action,
368+
headers,
369+
customRequest,
370+
withCredentials,
371+
} = this.props;
366372

367373
const request = customRequest || Request;
368374

@@ -373,6 +379,7 @@ class RUG extends React.Component {
373379
send,
374380
action,
375381
headers,
382+
withCredentials,
376383

377384
onError: this.onError,
378385
onSuccess: this.onSuccess,

src/Request.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ const Request = ({
66
file,
77
action,
88
headers,
9+
withCredentials,
910

1011
onProgress,
1112
onSuccess,
12-
onError
13+
onError,
1314
}) => {
1415
const xhr = new XMLHttpRequest();
1516

@@ -56,6 +57,10 @@ const Request = ({
5657

5758
xhr.open("POST", action, true);
5859

60+
if (withCredentials) {
61+
xhr.withCredentials = true;
62+
}
63+
5964
// if the value is null by default, the request will not be executed
6065
if (headers["X-Requested-With"] !== null) {
6166
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
@@ -84,7 +89,7 @@ const Request = ({
8489
return {
8590
abort() {
8691
xhr.abort();
87-
}
92+
},
8893
};
8994
};
9095

0 commit comments

Comments
 (0)