Skip to content

Commit

Permalink
Added XMLHttpRequest withCredentials property #36
Browse files Browse the repository at this point in the history
  • Loading branch information
m-inan committed Jun 3, 2022
1 parent d453da4 commit 9cb99ff
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ A library that will make things easier within the React framework for galleries
| `footer` | `Bolean` Or `Function` | `false` | `function({ images, accept, uploadFiles, openDialogue })` |
| `rules` | `Object` | `null` | `size`,` limit`, `width`,` height` features can be limited. [Rules](#Rules) |
| `customRequest` | `Function` | `null` | You can customize the http request in your own way. [CustomRequest](#CustomRequest) |
| `withCredentials` | `Boolean` | `false` | [XMLHttpRequest.withCredentials](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials) |
| `source` | `Function` | `null` | Enter the url of the photo from the returned answer. `(response) => response.url` |
| `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 })` |
| `onSuccess` | `Function` | `empty` | Return for uploaded image. `function(image)` |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-upload-gallery",
"version": "0.4.0",
"version": "0.4.1",
"license": "MIT",
"author": "Muhammet INAN",
"repository": {
Expand Down
2 changes: 2 additions & 0 deletions src/PropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const defaultProps = {
rules: null,

customRequest: null,
withCredentials: false,
source: null,
alias: null,

Expand Down Expand Up @@ -84,6 +85,7 @@ export const propTypes = {
}),

customRequest: PropTypes.func,
withCredentials: PropTypes.bool,
source: PropTypes.func,
alias: PropTypes.func,

Expand Down
9 changes: 8 additions & 1 deletion src/RUG.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,13 @@ class RUG extends React.Component {
}

upload({ uid, file, data }, finish) {
const { send, action, headers, customRequest } = this.props;
const {
send,
action,
headers,
customRequest,
withCredentials,
} = this.props;

const request = customRequest || Request;

Expand All @@ -373,6 +379,7 @@ class RUG extends React.Component {
send,
action,
headers,
withCredentials,

onError: this.onError,
onSuccess: this.onSuccess,
Expand Down
9 changes: 7 additions & 2 deletions src/Request.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ const Request = ({
file,
action,
headers,
withCredentials,

onProgress,
onSuccess,
onError
onError,
}) => {
const xhr = new XMLHttpRequest();

Expand Down Expand Up @@ -56,6 +57,10 @@ const Request = ({

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

if (withCredentials) {
xhr.withCredentials = true;
}

// if the value is null by default, the request will not be executed
if (headers["X-Requested-With"] !== null) {
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
Expand Down Expand Up @@ -84,7 +89,7 @@ const Request = ({
return {
abort() {
xhr.abort();
}
},
};
};

Expand Down

0 comments on commit 9cb99ff

Please sign in to comment.