Skip to content

Commit 5d845cd

Browse files
committed
feat: 增加表单 API 签名算法和客户端上传演示
1 parent 4368b8b commit 5d845cd

File tree

8 files changed

+515
-1
lines changed

8 files changed

+515
-1
lines changed

examples/client-upload/Readme.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## 客户端上传
2+
3+
本示例展示了如何使用表单 API, 直接从客户端进行安全的文件上传, 这种方式不需要客户服务器进行中转, 节省了客户服务器流量, 并且支持 HTTP/HTTPS 两种协议
4+
5+
DEMO 使用 `sdkimg` 空间进行演示, 上传成功后, 访问路径为 `http://sdkimg.b0.upaiyun.com/` 拼接保存路径
6+
7+
#### 运行示例
8+
9+
- `cd examples/client-upload`
10+
- `php -S localhost:9000`
11+
12+
打开浏览器访问 `http://localhost:9000`, 选则文件上传即可.

examples/client-upload/index.html

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Document</title>
6+
<link rel="stylesheet" href="normalize.css">
7+
<script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js" type="text/javascript"></script>
8+
<style>
9+
form {
10+
margin: 30px 0;
11+
}
12+
.submit {
13+
display: inline-block;
14+
width: 100px;
15+
background: #02a3c6;
16+
border: none;
17+
color: #fff;
18+
line-height: 40px;
19+
text-align: center;
20+
cursor: pointer;
21+
}
22+
</style>
23+
</head>
24+
<body>
25+
26+
<form action="http://v0.api.upyun.com/sdkimg" id="demoForm" method="POST" enctype="multipart/form-data">
27+
<fieldset>
28+
<legend>Client Upload Demo</legend>
29+
<input name="file" type="file">
30+
<input name="policy" type="hidden" id="policy">
31+
<input name="signature" type="hidden" id="signature">
32+
<input type="submit" value="submit" class="submit" id="submit">
33+
</fieldset>
34+
</form>
35+
36+
<script>
37+
// 文件保存的路径
38+
var save_path = '/test/filename.txt';
39+
// 获取 policy 和 secret
40+
$.getJSON('http://localhost:9000/policy.php?save_path=/test/filename.txt', function (data) {
41+
document.getElementById('policy').value = data.policy;
42+
document.getElementById('signature').value = data.signature;
43+
});
44+
</script>
45+
</body>
46+
</html>

0 commit comments

Comments
 (0)