Repository navigation
Expand file tree
/
Copy pathchunk-upload.js
More file actions
78 lines (76 loc) · 2.88 KB
/
Copy pathchunk-upload.js
File metadata and controls
78 lines (76 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
this.default = function () {
var dropElement = document.getElementsByClassName('control-fluid')[0];
// initialize the uploader component
var uploadObj = new ej.inputs.Uploader({
maxFileSize: 104857600,
asyncSettings: {
saveUrl: 'https://aspnetmvc.syncfusion.com/services/api/uploadbox/Save',
removeUrl: 'https://aspnetmvc.syncfusion.com/services/api/uploadbox/Remove',
chunkSize: 500000
},
autoUpload: false,
removing: onFileRemove,
dropArea: dropElement,
chunkFailure: onBeforeFailure,
pausing: onPausing,
resuming: onResuming
});
uploadObj.appendTo('#fileupload');
var isInteraction = false;
// to update flag variable value for automatic pause and resume
function onPausing(args) {
if (args.event !== null && !navigator.onLine) {
isInteraction = true;
}
else {
isInteraction = false;
}
}
// to update flag variable for automatic pause and resume
function onResuming(args) {
if (args.event !== null && !navigator.onLine) {
isInteraction = true;
}
else {
isInteraction = false;
}
}
function onFileRemove(args) {
args.postRawFile = false;
}
// initialize dropdown component
var listObj = new ej.dropdowns.DropDownList({
// set the index value to select an item based on index at initial rendering
index: 0,
// set the placeholder to DropDownList input element
placeholder: 'Select chunk size',
// set the height of the popup element
popupHeight: '200px',
// bind the change event
change: function (e) {
uploadObj.asyncSettings.chunkSize = parseInt(e.itemData.value, 10);
}
});
listObj.appendTo('#chunk-sizes');
// to prevent triggering chunk-upload failure event and to pause uploading on network failure
function onBeforeFailure(args) {
args.cancel = !isInteraction;
var uploadObj = document.getElementById('fileupload').ej2_instances[0];
// interval to check network availability on every 500 milliseconds
var clearTimeInterval = setInterval(function () {
if (navigator.onLine && !ej.base.isNullOrUndefined(uploadObj.filesData[0]) && uploadObj.filesData[0].statusCode == 4) {
uploadObj.resume(uploadObj.filesData);
clearSetInterval();
}
else {
if (!isInteraction && !ej.base.isNullOrUndefined(uploadObj.filesData[0]) && uploadObj.filesData[0].statusCode == 3) {
uploadObj.pause(uploadObj.filesData);
}
}
}, 500);
// clear Interval after when network is available.
function clearSetInterval() {
clearInterval(clearTimeInterval);
}
}
};