MCPcopy Index your code
hub / github.com/TruthHun/BookStack / fileUploadXhr

Function fileUploadXhr

static/js/jquery.form.js:282–341  ·  view source on GitHub ↗
(a)

Source from the content-addressed store, hash-verified

280
281 // XMLHttpRequest Level 2 file uploads (big hat tip to francois2metz)
282 function fileUploadXhr(a) {
283 var formdata = new FormData();
284
285 for (var i=0; i < a.length; i++) {
286 formdata.append(a[i].name, a[i].value);
287 }
288
289 if (options.extraData) {
290 var serializedData = deepSerialize(options.extraData);
291 for (i=0; i < serializedData.length; i++) {
292 if (serializedData[i]) {
293 formdata.append(serializedData[i][0], serializedData[i][1]);
294 }
295 }
296 }
297
298 options.data = null;
299
300 var s = $.extend(true, {}, $.ajaxSettings, options, {
301 contentType: false,
302 processData: false,
303 cache: false,
304 type: method || 'POST'
305 });
306
307 if (options.uploadProgress) {
308 // workaround because jqXHR does not expose upload property
309 s.xhr = function() {
310 var xhr = $.ajaxSettings.xhr();
311 if (xhr.upload) {
312 xhr.upload.addEventListener('progress', function(event) {
313 var percent = 0;
314 var position = event.loaded || event.position; /*event.position is deprecated*/
315 var total = event.total;
316 if (event.lengthComputable) {
317 percent = Math.ceil(position / total * 100);
318 }
319 options.uploadProgress(event, position, total, percent);
320 }, false);
321 }
322 return xhr;
323 };
324 }
325
326 s.data = null;
327 var beforeSend = s.beforeSend;
328 s.beforeSend = function(xhr, o) {
329 //Send FormData() provided by user
330 if (options.formData) {
331 o.data = options.formData;
332 }
333 else {
334 o.data = formdata;
335 }
336 if(beforeSend) {
337 beforeSend.call(this, xhr, o);
338 }
339 };

Callers 1

jquery.form.jsFile · 0.85

Calls 2

deepSerializeFunction · 0.85
extendMethod · 0.80

Tested by

no test coverage detected