Skip to content

Commit be59e16

Browse files
committed
a form upload
1 parent 4b1127e commit be59e16

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

demo/js/form-upload.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
$(function() {
2+
$.ajax({
3+
url: '/uptoken'
4+
}).done(function(obj) {
5+
console.log('========>token:', obj);
6+
console.log('========>token val:', obj.uptoken);
7+
$('#form-token').val(obj.uptoken);
8+
var tk = document.getElementById('form-token');
9+
console.log('=========>>', tk);
10+
tk.value = obj.uptoken;
11+
});
12+
});

demo/server.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,18 @@ app.get('/', function(req, res) {
6565
uptoken_url: config.Uptoken_Url
6666
});
6767
});
68+
app.get('/form.html', function(req, res) {
69+
res.render('form.html', {
70+
domain: config.Domain,
71+
uptoken_url: config.Uptoken_Url
72+
});
73+
});
6874

6975
qiniu.conf.ACCESS_KEY = config.ACCESS_KEY;
7076
qiniu.conf.SECRET_KEY = config.SECRET_KEY;
7177

72-
var uptoken = new qiniu.rs.PutPolicy(config.Bucket_Name);
78+
//function PutPolicy(scope, callbackUrl, callbackBody, returnUrl, returnBody,asyncOps, endUser, expires)
79+
var uptoken = new qiniu.rs.PutPolicy(config.Bucket_Name, '', '', '', '{"fname": $(fname), "x:content": "I am rwf", "suffix": "$(suffix)"}'); //, 'http://www.baidu.com', '{}');
7380

7481

7582
app.listen(config.Port, function() {

demo/views/form.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>七牛云存储 - JavaScript SDK</title>
6+
<link href="favicon.ico" rel="shortcut icon">
7+
<link rel="stylesheet" href="bootstrap/css/bootstrap.css">
8+
<link rel="stylesheet" href="js/highlight/highlight.css">
9+
</head>
10+
<body>
11+
<div class="container">
12+
<form method="post" action="http://up.qiniu.com/" enctype="multipart/form-data">
13+
<input name="token" id="form-token" type="hidden" value="">
14+
<input name="file" type="file" />
15+
<button>提交</button>
16+
</form>
17+
</div>
18+
19+
<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
20+
<script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
21+
<script type="text/javascript" src="/js/highlight/highlight.js"></script>
22+
<script type="text/javascript" src="/js/form-upload.js"></script>
23+
</body>
24+
</html>

0 commit comments

Comments
 (0)