-
Notifications
You must be signed in to change notification settings - Fork 0
/
Index.cshtml
96 lines (84 loc) · 2.73 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
@using ASP_NET_Core.Models
<script type="text/javascript" src="~/js/amazon.filesystem.js"></script>
<script type="text/javascript" src="~/js/amazon.gateway.js"></script>
<div id="wrapper">
<div id="widget-area">
@(Html.DevExtreme().FileUploader()
.ID("file-uploader")
.ChunkSize(5242880)
.UploadChunk("uploadChunk")
.AbortUpload("abortUpload")
.OnValueChanged("onValueChanged")
.OnUploaded("onUploaded")
)
<div id="download-panel"></div>
<div id="request-panel"></div>
</div>
@(Html.DevExtreme().LoadPanel()
.ID("load-panel")
.Visible(true)
.Position(p => p.Of("#widget-area"))
)
<div id="message-box">
To run the demo locally, specify your Amazon access key, secret key, region and bucket name in the appsettings.json file in your back-end app.
</div>
</div>
<script>
$.ajax({
url: 'https://localhost:52366/api/AmazonS3/getItems',
success(result) {
result.active = true;
const className = result.active ? 'show-widget' : 'show-message';
$('#wrapper').addClass(className);
$("#load-panel").dxLoadPanel("hide");
},
error() {
$("#load-panel").dxLoadPanel("hide");
}
});
async function onUploaded(e) {
const url = await amazon.getPresignedDownloadUrl(e.file.name);
showPresignedUrl(url, e.file.name);
}
async function abortUpload(file, uploadInfo) {
return amazon.abortUpload(file, uploadInfo);
}
function onValueChanged(e) {
hidePresignedUrl();
}
async function uploadChunk(file, uploadInfo) {
return amazon.uploadFileChunk(file, uploadInfo);
};
function showPresignedUrl(url, fileName) {
$('<div>')
.attr('id', 'url-div')
.append(
$('<span>').text('Download uploaded file: '),
$('<a>')
.attr('href', url)
.attr('target', '_blank')
.text(fileName)
)
.appendTo('#download-panel');
}
function hidePresignedUrl() {
$('#url-div').remove();
}
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:52366/api/AmazonS3';
const amazon = new AmazonFileSystem(endpointUrl, onRequestExecuted);
</script>