Skip to content

Commit

Permalink
feat($UI): add large file upload demo page
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnymillergh committed Aug 18, 2021
1 parent 17cbdf0 commit 8d51be4
Show file tree
Hide file tree
Showing 18 changed files with 204 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private void postConstruct() {
@ApiOperation(value = "/home", notes = "Home page")
public void handleHomeRequest(HttpServletResponse response) throws IOException {
// Redirect to home page
response.sendRedirect("static/home.html");
response.sendRedirect("static/home/index.html");
}

@GetMapping("/doc")
Expand All @@ -47,6 +47,6 @@ public void handleDocRequest(HttpServletResponse response) throws IOException {
@ApiOperation(value = "/webjars/bycdao-ui/images/api.ico", notes = "Favicon redirection")
public void handleFaviconRequest(HttpServletResponse response) throws IOException {
// Redirect to a customized favicon
response.sendRedirect("/static/icon/favicon.ico");
response.sendRedirect("/static/asset/favicon.ico");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ public String getPresignedObjectUrl(@NotBlank String bucket, @NotBlank String ob

@SneakyThrows
public ObjectWriteResponse composeObject(@NotBlank String bucket, @NotBlank String object,
@NotEmpty List<ComposeSource> sources,@Nullable Map<String, String> headers) {
@NotEmpty List<ComposeSource> sources,
@Nullable Map<String, String> headers) {
if (!this.bucketExists(bucket)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<head>
<meta charset="UTF-8">
<title>UNSET</title>
<link href="icon/favicon.ico" rel="icon">
<link href="style/home.css" rel="stylesheet">
<link href="../asset/favicon.ico" rel="icon">
<link href="index.css" rel="stylesheet">
</head>
<body>
<div id="app">
Expand All @@ -18,7 +18,7 @@
<button @click="handleClickVideoDemo" class="go-to">Go to Video Demo</button>
<span class="application-name">{{ applicationName }}</span>
<img alt="Muscle And Fitness Server Social Image" class="social-image"
src="image/muscle-and-fitness-server-social-image.png">
src="../asset/muscle-and-fitness-server-social-image.png">
</div>
<fieldset>
<legend>Create New Person</legend>
Expand Down Expand Up @@ -74,5 +74,5 @@
</div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script src="script/home.js"></script>
<script src="index.js"></script>
</html>
72 changes: 72 additions & 0 deletions universal-ui/src/main/resources/static/large-file-upload/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
* {
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
}

body {
font-family: 'Montserrat', sans-serif;
background: #535c68;
}

.wrapper {
margin: auto;
max-width: 640px;
padding-top: 60px;
text-align: center;
}

.container {
background-color: #f9f9f9;
padding: 20px;
border-radius: 10px;
/*border: 0.5px solid rgba(130, 130, 130, 0.25);*/
/*box-shadow: 0 2px 3px rgba(0, 0, 0, 0.1),
0 0 0 1px rgba(0, 0, 0, 0.1);*/
}

h1 {
color: #130f40;
font-family: 'Varela Round', sans-serif;
letter-spacing: -.5px;
font-weight: 700;
padding-bottom: 10px;
}

.upload-container {
background-color: rgb(239, 239, 239);
border-radius: 6px;
padding: 10px;
}

.border-container {
border: 5px dashed rgba(198, 198, 198, 0.65);
/* border-radius: 4px; */
padding: 20px;
}

.border-container p {
color: #130f40;
font-weight: 600;
font-size: 1.1em;
letter-spacing: -1px;
margin-top: 30px;
margin-bottom: 0;
opacity: 0.65;
}

#file-browser {
text-decoration: none;
color: rgb(22,42,255);
border-bottom: 3px dotted rgba(22, 22, 255, 0.85);
}

#file-browser:hover {
color: rgb(0, 0, 255);
border-bottom: 3px dotted rgba(0, 0, 255, 0.85);
}

.icons {
color: #95afc0;
opacity: 0.55;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Large File Upload Demo</title>
<link href="../asset/favicon.ico" rel="icon">
<link href="index.css" rel="stylesheet">
<link href="https://use.fontawesome.com/releases/v5.0.10/css/all.css" rel="stylesheet">
</head>
<body>
<div id="app">
<div class="wrapper">
<div class="container">
<h1>Upload a file</h1>
<div class="upload-container">
<div class="border-container">
<div class="icons fa-4x">
<i class="fas fa-file-image" data-fa-transform="shrink-3 down-2 left-6 rotate--45"></i>
<i class="fas fa-file-alt" data-fa-transform="shrink-2 up-4"></i>
<i class="fas fa-file-pdf" data-fa-transform="shrink-3 down-2 right-6 rotate-45"></i>
</div>
<input @change="onFilePicked" id="file-input" type="file">
<p>Drag and drop files here, or <a href="#" id="file-browser">browse</a> your computer.</p>
</div>
</div>
</div>
</div>
</div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script src="https://use.fontawesome.com/releases/v5.0.10/js/all.js"></script>
<script src="index.js"></script>
</html>
85 changes: 85 additions & 0 deletions universal-ui/src/main/resources/static/large-file-upload/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// 64 megabytes
const BYTES_PER_CHUNK = 64 * 1048576
// noinspection JSUnresolvedFunction
new Vue({
el: '#app',
data: {
appInfo: null,
videoSource: '',
split: window.location.href.split('/')
},
methods: {
async onFilePicked(event) {
const files = event.target.files
const blob = files[0]
console.info('blob', blob)
let startByte = 0
let endByte = 0
let index = 0
const slices = Math.ceil(blob.size / BYTES_PER_CHUNK)
const uploadResourceChunkPayload = {
bucket: '',
filename: blob.name
}
const objectList = []
while (startByte < blob.size) {
endByte = startByte + BYTES_PER_CHUNK
if (endByte > blob.size) {
endByte = blob.size
}
const response = await this.uploadResourceChunk(blob, index, startByte, endByte, uploadResourceChunkPayload)
objectList.push(response.data.object)
console.info('response', response)
if (index === 0) {
uploadResourceChunkPayload.bucket = response.data.bucket
console.warn('Set uploadResourceChunkPayload', uploadResourceChunkPayload)
}
startByte = endByte
index++
if (index >= slices) {
if (slices === 1) {
console.error(`The slices count is ${slices}, should not be Uploaded by chunk`)
}
console.info(`Finished uploading all chunks. index >= slices. index = ${index}, slice = ${slices}`);
const mergeResponse = await this.mergeResourceChunk(uploadResourceChunkPayload.bucket, objectList);
console.info('Finished merging all chunks', mergeResponse);
}
}
},
async uploadResourceChunk(blob, index, start, end, uploadResourceChunkPayload) {
console.info(`uploadFile blog: ${blob}, index: ${index}, start: ${start}, end: ${end}, uploadResourceChunkPayload: `, uploadResourceChunkPayload)
const formData = new FormData()
formData.append('bucket', uploadResourceChunkPayload.bucket)
formData.append('chunkNumber', index)
formData.append('filename', uploadResourceChunkPayload.filename)
formData.append('file', blob.slice(start, end))
const url = `${this.split[0]}//${this.split[2]}/upload/chunk`
const resp = await fetch(url, {
method: 'POST',
body: formData,
headers: {
'Content-Disposition': `form-data; name="file"; filename="${blob.name}"`
}
})
return await resp.json()
},
async mergeResourceChunk(bucket, objectList) {
const mergeResourcePayload = {
'bucket': bucket,
'objectList': objectList
}
const url = `${this.split[0]}//${this.split[2]}/merge/chunk`
const resp = await fetch(url, {
method: 'PUT',
body: JSON.stringify(mergeResourcePayload),
headers: {
'Content-Type': 'application/json'
}
})
return await resp.json()
}
},
mounted() {
console.log('mounted')
}
});
12 changes: 0 additions & 12 deletions universal-ui/src/main/resources/static/script/404.js

This file was deleted.

89 changes: 0 additions & 89 deletions universal-ui/src/main/resources/static/style/404.css

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<head>
<meta charset="UTF-8">
<title>ExRx.net Crawler Server</title>
<link href="icon/favicon.ico" rel="icon">
<link href="style/video.css" rel="stylesheet">
<link href="../asset/favicon.ico" rel="icon">
<link href="index.css" rel="stylesheet">
</head>
<body>
<div id="app">
Expand All @@ -21,5 +21,5 @@
</div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script src="script/video.js"></script>
<script src="index.js"></script>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ const vm = new Vue({
videoSource: ''
},
async mounted() {
const currentUrl = window.location.href;
const split = currentUrl.split('/');
const split = window.location.href.split('/');
this.videoSource = `${split[0]}//${split[2]}/${split[3]}/test-table/demo-video`;
const baseUrl = `${split[0]}//${split[2]}`;
const response = await fetch(`${baseUrl}/common/app-info`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta content="width=device-width, initial-scale=1.0, minimum-scale=1.0" name="viewport">
<title>Spring Boot WebSocket Chat Application | CalliCoder</title>
<link href="style/websocket.css" rel="stylesheet"/>
<link href="index.css" rel="stylesheet"/>
</head>
<body>
<noscript>
Expand Down Expand Up @@ -49,6 +49,6 @@ <h2>Spring WebSocket Chat Demo</h2>

<script src="https://cdnjs.cloudflare.com/ajax/libs/sockjs-client/1.5.1/sockjs.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/stomp.js/2.3.3/stomp.min.js"></script>
<script src="script/websocket.js"></script>
<script src="index.js"></script>
</body>
</html>

0 comments on commit 8d51be4

Please sign in to comment.