(js) Add support for XSRF token with file uploader

This commit is contained in:
Francis Lachapelle
2016-05-02 09:34:43 -04:00
parent 6c84a7b7cc
commit f190ad1c3c
4 changed files with 36 additions and 14 deletions
@@ -0,0 +1,27 @@
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
(function() {
'use strict';
/**
* Set XSRF header if the cookie exists.
* Solution based on the following discussion:
* https://github.com/nervgh/angular-file-upload/issues/360
*/
angular
.module('angularFileUpload')
.decorator('FileUploader', FileUploaderDecorator);
/**
* @ngInject
*/
FileUploaderDecorator.$inject = ['$delegate', '$cookies'];
function FileUploaderDecorator($delegate, $cookies) {
$delegate.prototype.onBeforeUploadItem = function(item) {
var token = $cookies.get('XSRF-TOKEN');
if (token)
item.headers = {'X-XSRF-TOKEN': token};
};
return $delegate;
}
})();
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long