-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathIndex.cshtml
76 lines (70 loc) · 2.67 KB
/
Index.cshtml
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
@using ASP_NET_Core.Models
<script src="~/services/azure.gateway.js"></script>
<div id="wrapper">
<div id="widget-area">
@(Html.DevExtreme().FileUploader()
.ID("file-uploader")
.ChunkSize(200000)
.MaxFileSize(1048576)
.UploadChunk("uploadChunk")
)
<div id="request-panel"></div>
</div>
@(Html.DevExtreme().LoadPanel()
.ID("load-panel")
.Visible(true)
.Position(p => p.Of("#file-uploader"))
)
<div id="message-box">
To run the demo locally, specify your Azure storage account name, access key and container name in the appsettings.json file in your back-end app.
</div>
</div>
<script>
$.ajax({
url: 'https://localhost:7021/api/file-azure-status?widgetType=fileUploader',
success(result) {
const className = result.active ? 'show-widget' : 'show-message';
$('#wrapper').addClass(className);
$("#load-panel").dxLoadPanel("hide");
},
error() {
$("#load-panel").dxLoadPanel("hide");
}
});
function uploadChunk(file, uploadInfo) {
let promise = null;
if (uploadInfo.chunkIndex === 0) {
promise = gateway.getUploadAccessUrl(file.name).then(function (accessUrls) {
uploadInfo.customData.accessUrl = accessUrls.url1;
});
} else {
promise = Promise.resolve();
}
promise = promise.then(function () {
return gateway.putBlock(uploadInfo.customData.accessUrl, uploadInfo.chunkIndex, uploadInfo.chunkBlob);
});
if (uploadInfo.chunkIndex === uploadInfo.chunkCount - 1) {
promise = promise.then(function () {
return 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)
);
}
const endpointUrl = 'https://localhost:7021/api/file-uploader-azure-access';
const gateway = new AzureGateway(endpointUrl, onRequestExecuted);
</script>