Skip to content

Commit d32f027

Browse files
committed
0.4: Add example: custom-signature.html
1 parent 83c8394 commit d32f027

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

examples/native-custom-signature.html

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>又拍云表单上传工具 | upyun form uploader</title>
6+
<link rel="stylesheet" href="./style.css">
7+
<script src="../dist/upyun.min.js"></script>
8+
</head>
9+
<body>
10+
<div class="wrapper">
11+
<h2>又拍云表单上传演示 <span>Native javascript</span></h2>
12+
<div id="preview" class="preview"></div>
13+
<form name="uploadForm" role="form">
14+
<input type="file" name="file">
15+
<a class="submit" id="submitToUpyun" onclick="upload();">Upload</a>
16+
</form>
17+
</div>
18+
<script>
19+
// just for demo !!!
20+
// this bucket has a upload limit
21+
upyun.set('policy','eyJmb3JtX2FwaV9zZWNyZXQiOiJJUm9UeU5jNzVodXNmUUQyNGNxMGJObVJTREk9IiwiYnVja2V0IjoidXB5dW4tZm9ybSIsImV4cGlyYXRpb24iOjE0MjAzNzQ0ODU1NjgsInNhdmUta2V5IjoiL3t5ZWFyfS97bW9ufS97ZGF5fS91cGxvYWRfe2ZpbGVtZDV9ey5zdWZmaXh9IiwiYWxsb3ctZmlsZS10eXBlIjoianBnLGpwZWcsZ2lmLHBuZyJ9');
22+
upyun.set('signature', 'd1eb1c203c1bc847cc555442cf99d6ef');
23+
// track uploading progress
24+
upyun.on('uploading', function(progress) {
25+
console.log('上传进度 ' + progress + '%');
26+
document.getElementById('submitToUpyun').innerText =
27+
progress === 100 ?
28+
'上传完成' :
29+
'上传进度 ' + progress + '%';
30+
});
31+
// upload method
32+
function upload() {
33+
console.log('正在开始上传...');
34+
upyun.upload('uploadForm', function(err, response, image){
35+
if (err) console.error(err);
36+
console.log('返回信息:');
37+
console.log(response);
38+
console.log('图片信息:');
39+
console.log(image);
40+
if (image.code === 200 && image.message === 'ok') {
41+
document.getElementById('preview').innerHTML = [
42+
'<img alt="" src="',
43+
image.absUrl,
44+
'" />'
45+
].join('\n');
46+
}
47+
});
48+
return false;
49+
}
50+
</script>
51+
</body>
52+
</html>

0 commit comments

Comments
 (0)