forked from harshavardhana/minio-js-browser-upload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
39 lines (33 loc) · 959 Bytes
/
index.html
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
<input type="file" id="selector" multiple>
<button onclick="upload()">Upload</button>
<div id="status">No uploads</div>
<script src="//code.jquery.com/jquery-3.1.0.min.js"></script>
<script type="text/javascript">
function upload() {
[$('#selector')[0].files].forEach(fileObj => {
var file = fileObj[0]
// Retrieve a URL from our server.
retrieveNewURL(file, url => {
// Upload the file to the server.
uploadFile(file, url)
})
})
}
// Request to our Node.js server for an upload URL.
function retrieveNewURL(file, cb) {
$.get(`/presignedUrl?name=${file.name}`, (url) => {
cb(url)
})
}
// Use XMLHttpRequest to upload the file to S3.
function uploadFile(file, url) {
var xhr = new XMLHttpRequest ()
xhr.open('PUT', url, true)
xhr.send(file)
xhr.onload = () => {
if (xhr.status == 200) {
$('#status').text(`Uploaded ${file.name}.`)
}
}
}
</script>