-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
69 lines (58 loc) · 1.85 KB
/
index.js
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
$(() => {
const loadPanel = $('#load-panel').dxLoadPanel({
position: { of: '#file-uploader' },
}).dxLoadPanel('instance');
$.ajax({
url: 'https://localhost:7021/api/file-azure-status?widgetType=fileUploader',
success(result) {
const className = result.active ? 'show-widget' : 'show-message';
$('#wrapper').addClass(className);
loadPanel.hide();
},
});
const endpointUrl = 'https://localhost:7021/api/file-uploader-azure-access';
gateway = new AzureGateway(endpointUrl, onRequestExecuted);
$('#file-uploader').dxFileUploader({
chunkSize: 200000,
maxFileSize: 1048576,
uploadChunk,
});
});
function uploadChunk(file, uploadInfo) {
let promise = null;
if (uploadInfo.chunkIndex === 0) {
promise = gateway.getUploadAccessUrl(file.name).then((accessUrl) => {
uploadInfo.customData.accessUrl = accessUrl.url1;
});
} else {
promise = Promise.resolve();
}
promise = promise.then(() => gateway.putBlock(
uploadInfo.customData.accessUrl,
uploadInfo.chunkIndex,
uploadInfo.chunkBlob,
));
if (uploadInfo.chunkIndex === uploadInfo.chunkCount - 1) {
promise = promise.then(() => gateway.putBlockList(
uploadInfo.customData.accessUrl,
uploadInfo.chunkCount,
));
}
return promise;
}
function onRequestExecuted(e) {
$('<div>').addClass('request-info').append(
createParameterInfoDiv('Method:', e.method),
createParameterInfoDiv('Url path:', e.urlPath),
createParameterInfoDiv('Query string:', e.queryString),
$('<br>'),
)
.prependTo('#request-panel');
}
function createParameterInfoDiv(name, value) {
return $('<div>').addClass('parameter-info').append(
$('<div>').addClass('parameter-name').text(name),
$('<div>').addClass('parameter-value dx-theme-accent-as-text-color').text(value).attr('title', value),
);
}
let gateway = null;