-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.html
35 lines (34 loc) · 1.23 KB
/
upload.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
<!DOCTYPE html>
<html lang="en" >
<head>
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="bower_components/js-md5/js/md5.min.js"></script>
<script src="assets/utils.js"></script>
<script>
$(document).ready(function(){
$(':file').change(function(){
var file = this.files[0];
var reader = new FileReader();
reader.onload = function(e) {
var rawData = reader.result;
upload('huangchaosuper','huangchaosuper','http://v0.api.upyun.com/huangchaosuper-files/' + file.name,rawData);
}
reader.readAsBinaryString(file);
});
});
function upload(username,password,path,data){
var authorization = 'Basic ' + base64encode(username+':'+password);
var xhr = new XMLHttpRequest();
xhr.open('PUT', path, true);
xhr.setRequestHeader("Origin","*");
xhr.setRequestHeader("Authorization",authorization);
xhr.send(data);
}
</script>
<title>upload test</title>
</head>
<body>
<form id="uploadForm" name="uploadForm" enctype="multipart/form-data">
<input id="uploadfile" type="file" name="file">
</form>
</body>