<div>
<h1>File upload progress</h1>
<input type="file" id="file-uploader">
<div id="feedback">
</div>
<label id="progress-label" for="progress"></label>
<progress id="progress" value="0" max="100"> </progress>
</div>
html {
height: 100%;
}
body {
background: #000000;
color: #FFFFFF;
}
div {
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
font-family: 'Roboto Mono', monospace;
}
div#feedback {
padding: 10px;
}
const fileUploader = document.getElementById('file-uploader');
const feedback = document.getElementById('feedback');
const progress = document.getElementById('progress');
const reader = new FileReader();
fileUploader.addEventListener('change', (event) => {
const files = event.target.files;
const file = files[0];
reader.readAsDataURL(file);
reader.addEventListener('progress', (event) => {
if (event.loaded && event.total) {
const percent = (event.loaded / event.total) * 100;
progress.value = percent;
document.getElementById('progress-label').innerHTML = Math.round(percent) + '%';
if (percent === 100) {
let msg = `<span style="color:green;">File <u><b>${file.name}</b></u> has been uploaded successfully.</span>`;
feedback.innerHTML = msg;
}
}
});
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.