This repository was archived by the owner on Mar 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathindex.html
163 lines (150 loc) · 4.52 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<!DOCTYPE html>
<html lang="en" style="width: 100%;height: 100%">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body, html {
width: 100%;
height: 100%;
}
#button {
height: 80px;
width: 200px;
font-size: 30px;
}
</style>
</head>
<body>
<button id="button">
上传文件
</button>
<div id="content"></div>
<script src="http://qtestbucket.qiniudn.com/demo/CryptoJS.js"></script>
<script src="dist/qiniu4js.js"></script>
<script>
/* utf.js - UTF-8 <=> UTF-16 convertion
*
* Copyright (C) 1999 Masanao Izumo <iz@onicos.co.jp>
* Version: 1.0
* LastModified: Dec 25 1999
* This library is free. You can redistribute it and/or modify it.
*/
/*
* Interfaces:
* utf8 = utf16to8(utf16);
* utf16 = utf8to16(utf8);
*/
function utf16to8 (str) {
var out, i, len, c
out = ''
len = str.length
for (i = 0; i < len; i++) {
c = str.charCodeAt(i)
if ((c >= 0x0001) && (c <= 0x007F)) {
out += str.charAt(i)
} else if (c > 0x07FF) {
out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F))
out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F))
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F))
} else {
out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F))
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F))
}
}
return out
}
/*
* Interfaces:
* b64 = base64encode(data);
* data = base64decode(b64);
*/
var base64EncodeChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'
function base64encode (str) {
var out, i, len
var c1, c2, c3
len = str.length
i = 0
out = ''
while (i < len) {
c1 = str.charCodeAt(i++) & 0xff
if (i === len) {
out += base64EncodeChars.charAt(c1 >> 2)
out += base64EncodeChars.charAt((c1 & 0x3) << 4)
out += '=='
break
}
c2 = str.charCodeAt(i++)
if (i === len) {
out += base64EncodeChars.charAt(c1 >> 2)
out += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4))
out += base64EncodeChars.charAt((c2 & 0xF) << 2)
out += '='
break
}
c3 = str.charCodeAt(i++)
out += base64EncodeChars.charAt(c1 >> 2)
out += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4))
out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6))
out += base64EncodeChars.charAt(c3 & 0x3F)
}
return out
}
var safe64 = function (base64) {
base64 = base64.replace(/\+/g, '-')
base64 = base64.replace(/\//g, '_')
return base64
}
function getToken (accessKey, secretKey, putPolicy) {
var put_policy = JSON.stringify(putPolicy)
var encoded = base64encode(utf16to8(put_policy))
var hash = CryptoJS.HmacSHA1(encoded, secretKey)
var encoded_signed = hash.toString(CryptoJS.enc.Base64)
return accessKey + ':' + safe64(encoded_signed) + ':' + encoded
}
function write (content) {
var str = document.getElementById('content').innerHTML
document.getElementById('content').innerHTML = str + '\n' + content.toString()
}
//qiniu test account
var bucket = 'test'
var ak = '7JlK6ZaNtH2R7ECXUF8u22mz6q7_Ka1lXwxli7C-'
var sk = 'PNUXmzor5VVYojmiE1WcM1HVUvZ8tfRKjZtkI-SH'
var putPolicy = {
scope: bucket,
deadline: 32508219230
}
window.onload = function () {
var qiniu = new Qiniu.UploaderBuilder()
.debug(true)
// .compress(0.5)
// .scale([640, 0])
.tokenShare(false)
.chunk(true)
.multiple(true)
.button('button')
.accept(['image/*'])
.tokenFunc(function (setToken) {
var token = getToken(ak, sk, putPolicy)
setToken(token)
}).listener({
onReady: function (tasks) {
write(tasks)
}, onStart: function (tasks) {
write(tasks)
}, onTaskProgress: function (task) {
write(task)
}, onTaskSuccess: function (task) {
write(task)
}, onTaskFail: function (task) {
write(task)
}, onTaskRetry: function (task) {
write(task)
}, onFinish: function (tasks) {
write(tasks)
}
}).build()
}
</script>
</body>
</html>