Closed prattcmp closed 6 years ago
+1
+10000
I've added manually:
function i(n) {
if (1 == u(n)) {
if (null != b) {
if (void 0 == b[n] || null == b[n]) return void K(n, {name: "InternalError", message: "There was an error uploading the file"});
if (window.FormData) {
var t = $.ajaxSettings.xhr();
if (t.upload) {
var a = b[n], o = new FormData;
f(o, F), o.append(C, a);
var token = $("meta[name='_csrf']").prop('content'), header = $("meta[name='_csrf_header']").prop('content'); // getting the tokenvalue and headername
var headers = {};
headers[header] = token;
var r = {
//putting it as headers:headers
url: e, data: o, headers: headers,type: "post", cache: !1, xhrFields: T, beforeSend: function (e) {
R[n].xhr = e
}, xhr: function () {
return t.upload.addEventListener("progress", function (e) {
e.lengthComputable && Y(n, e.loaded / e.total * 100)
}, !1), t
}, error: function () {
R[n].xhr = null, K(n, {name: "RequestError", message: "Could not get response from server"})
}, success: function (e) {
R[n].xhr = null, Y(n, 100), G(n, e)
}, contentType: !1, processData: !1
};
return "auto" != E && (r.dataType = E), void $.ajax(r)
}
}
}
"object" == typeof l && null !== l ? s(n) : K(n, {name: "UnsupportedError", message: "Your browser does not support this upload method"})
}
}
I know this is late, but you can now do this using the beforeSend
callback: See here
It is nearly identical to jQuery's beforeSend in that it takes a jqXHR
object and a settings
object and you can modify the XHR using this function, before the request is made. While not specific to CSRF, this now allows you to add headers to your requests.
What should I do if I need to send a CSRF token with the file?