Skip to content

Commit

Permalink
Merge pull request #86 from lsqlabs/with-credentials
Browse files Browse the repository at this point in the history
feat(*): allow setting XHR withCredentials
  • Loading branch information
dmayerdesign committed Apr 6, 2023
2 parents 59ac7d1 + 8d80913 commit 8ecfbdb
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 8 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ uploader.selectFiles();

## Advanced example (using Angular)

```javascript
```typescript
@Component({
selector: 'uploader-demo',
template: `
Expand All @@ -96,7 +96,7 @@ export class UploaderDemoComponent implements AfterViewInit {
],
fileCountLimit: 100,
fileSizeLimitMb: 10,
uploadFileAsBody: false // Default is false. When true, the file will be the body of the request, instead of being sent as form data.
uploadFileAsBody: false, // Default is false. When true, the file will be the body of the request, instead of being sent as form data.
onFileCountLimitExceeded: (fileCountLimit) => alert(
'You attempted to upload more than the limit of '
+ fileCountLimit + ' files'
Expand All @@ -107,7 +107,8 @@ export class UploaderDemoComponent implements AfterViewInit {
+ fileUpload.name,
headers: {
'content-length': `${fileUpload.file.size}`
}
},
withCredentials: false // Default is false. When true, the XHR withCredentials flag will be set to allow propagating cookies.
};
},
allFilesQueuedCallback: (fileUploads) => {
Expand Down Expand Up @@ -325,6 +326,7 @@ interface IUploadRequestOptions {
method?: HttpMethod;
formData?: FormData;
headers?: { [key: string]: string };
withCredentials?: boolean;
}

enum ProgressState {
Expand Down
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rxjs-uploader-demo",
"version": "1.5.1",
"version": "1.6.1",
"description": "A simple RxJS-powered interface for uploading files.",
"author": {
"name": "lsqlabs",
Expand Down
13 changes: 13 additions & 0 deletions projects/rxjs-uploader/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion projects/rxjs-uploader/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rxjs-uploader",
"version": "1.5.1",
"version": "1.6.1",
"license": "MIT",
"description": "A simple RxJS-powered interface for uploading files.",
"repository": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export interface IUploadRequestOptions {
method?: HttpMethod;
formData?: FormData | { [key: string]: string };
headers?: { [key: string]: string };
withCredentials?: boolean;
}
3 changes: 2 additions & 1 deletion projects/rxjs-uploader/src/lib/rxjs-uploader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ describe('RxJs Uploader', () => {

const uploader = new Uploader()
.setRequestOptions({
url: 'https://api.myawesomeservice.com/upload'
url: 'https://api.myawesomeservice.com/upload',
withCredentials: true
})
.setRequestOptionsFactory(async (fileUpload) => {
return {
Expand Down
2 changes: 1 addition & 1 deletion projects/rxjs-uploader/src/lib/rxjs-uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ export class Uploader<FileUploadType extends FileUpload = FileUpload> {
const progressStream = fromEvent(xhr.upload, 'progress');
const completedStream = fromEvent(xhr, 'load');
const xhrErrorStream = fromEvent(xhr, 'error');
xhr.withCredentials = false;
xhr.withCredentials = fileUpload.requestOptions.withCredentials || false;

this._subscribeTemporarily(
merge(progressStream, completedStream)
Expand Down

0 comments on commit 8ecfbdb

Please sign in to comment.