Bug fix. Ensure onCompleteItem and onErrorItem both reset the CSRF Header (for next item in queue), as onBeforeUploadItem does not seem to be called for every item in the queue.

This commit is contained in:
Tim Donohue
2021-03-01 16:51:56 -06:00
parent 4a72cb033b
commit 82035516a7

View File

@@ -155,12 +155,13 @@ export class UploaderComponent {
};
}
this.uploader.onCompleteItem = (item: any, response: any, status: any, headers: any) => {
// Check for a changed XSRF token in response & save new token if found
// Check for a changed XSRF token in response & save new token if found (to both cookie & header for next request)
// NOTE: this is only necessary because ng2-file-upload doesn't use an Http service and therefore never
// triggers our xsrf.interceptor.ts. See this bug: https://github.com/valor-software/ng2-file-upload/issues/950
const token = headers[XSRF_RESPONSE_HEADER.toLowerCase()];
if (isNotEmpty(token)) {
this.saveXsrfToken(token);
this.uploader.options.headers = [{ name: XSRF_REQUEST_HEADER, value: this.tokenExtractor.getToken() }];
}
if (isNotEmpty(response)) {
@@ -169,13 +170,15 @@ export class UploaderComponent {
}
};
this.uploader.onErrorItem = (item: any, response: any, status: any, headers: any) => {
// Check for a changed XSRF token in response & save new token if found
// Check for a changed XSRF token in response & save new token if found (to both cookie & header for next request)
// NOTE: this is only necessary because ng2-file-upload doesn't use an Http service and therefore never
// triggers our xsrf.interceptor.ts. See this bug: https://github.com/valor-software/ng2-file-upload/issues/950
const token = headers[XSRF_RESPONSE_HEADER.toLowerCase()];
if (isNotEmpty(token)) {
this.saveXsrfToken(token);
this.uploader.options.headers = [{ name: XSRF_REQUEST_HEADER, value: this.tokenExtractor.getToken() }];
}
this.onUploadError.emit({ item: item, response: response, status: status, headers: headers });
this.uploader.cancelAll();
};