-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
afad36a
commit 950bc98
Showing
4 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Frontend App | ||
|
||
## Start | ||
```commandline | ||
python3 -m http.server 8080 | ||
``` | ||
Open [http://localhost:8080](http://localhost:8080) in your browser. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>My Simple App</title> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
<body> | ||
<h1>My Simple App</h1> | ||
|
||
<label for="fileInput" class="file-upload-label">Upload a file:</label> | ||
<input type="file" id="fileInput" class="file-upload-input"> | ||
|
||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/resumable.min.js"></script> | ||
<script src="script.js"></script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Constants | ||
const API_URL = 'http://localhost:8000/api/files'; | ||
|
||
var r = new Resumable({ | ||
target: API_URL + '/upload', | ||
chunkSize: 1 * 1024 * 1024, // 1 MB | ||
simultaneousUploads: 3, | ||
testChunks: true, | ||
throttleProgressCallbacks: 1, | ||
}); | ||
|
||
// Event handlers | ||
r.on('fileAdded', function(file) { | ||
r.upload(); | ||
}); | ||
|
||
r.on('fileProgress', function(file) { | ||
console.log('File progress', file.progress()); | ||
}); | ||
|
||
r.on('fileSuccess', function(file, message) { | ||
console.log('File uploaded successfully', file); | ||
completeUpload(file); | ||
}); | ||
|
||
r.on('fileError', function(file, message) { | ||
console.error('File upload error', message); | ||
}); | ||
|
||
// Add a file input to trigger the upload | ||
document.getElementById('fileInput').addEventListener('change', function(event) { | ||
r.addFile(event.target.files[0]); | ||
}); | ||
|
||
function completeUpload(file) { | ||
fetch(API_URL + '/upload/complete', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
resumable_identifier: file.uniqueIdentifier, | ||
resumable_filename: file.fileName, | ||
}), | ||
}) | ||
.then(response => { | ||
if (!response.ok) { | ||
throw new Error('Failed to complete upload'); | ||
} | ||
return response.json(); | ||
}) | ||
.then(data => { | ||
console.log('Upload complete:', data); | ||
}) | ||
.catch(error => { | ||
console.error('Error completing upload:', error); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
text-align: center; | ||
margin-top: 50px; | ||
} | ||
|
||
.file-upload-label { | ||
display: inline-block; | ||
padding: 10px 20px; | ||
background-color: #007bff; | ||
color: white; | ||
border-radius: 5px; | ||
cursor: pointer; | ||
margin-top: 20px; | ||
} | ||
|
||
.file-upload-input { | ||
display: none; | ||
} |