Skip to content

Commit 8550b40

Browse files
committed
Merge pull request #15 from qiniupd/8430_demo_config_extract_to_backend
8430 demo config extract to backend
2 parents 5114b2a + 4535c48 commit 8550b40

File tree

5 files changed

+82
-72
lines changed

5 files changed

+82
-72
lines changed

demo/config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@ module.exports = {
22
'ACCESS_KEY': '<Your Access Key>',
33
'SECRET_KEY': '<Your Secret Key>',
44
'Bucket_Name': '<Your Bucket Name>',
5-
'Port': 18080
5+
'Port': 18080,
6+
'Uptoken_Url': '/token',
7+
'Domain': 'http://qiniu-plupload.qiniudn.com/'
68
}

demo/js/main.js

Lines changed: 66 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -3,77 +3,76 @@
33
/*global FileProgress */
44
/*global hljs */
55

6-
var uploader = Qiniu.uploader({
7-
runtimes: 'html5,flash,html4',
8-
browse_button: 'pickfiles',
9-
container: 'container',
10-
drop_element: 'container',
11-
max_file_size: '100mb',
12-
flash_swf_url: 'js/plupload/Moxie.swf',
13-
dragdrop: true,
14-
chunk_size: '4mb',
15-
uptoken_url: '/token',
16-
domain: 'http://qiniu-plupload.qiniudn.com/',
17-
// unique_names: true,
18-
// save_key: true,
19-
// x_vars: {
20-
// 'id': '1234',
21-
// 'time': function(up, file) {
22-
// var time = (new Date()).getTime();
23-
// // do something with 'time'
24-
// return time;
25-
// },
26-
// },
27-
auto_start: true,
28-
init: {
29-
'FilesAdded': function(up, files) {
30-
$('table').show();
31-
$('#success').hide();
32-
plupload.each(files, function(file) {
6+
$(function() {
7+
var uploader = Qiniu.uploader({
8+
runtimes: 'html5,flash,html4',
9+
browse_button: 'pickfiles',
10+
container: 'container',
11+
drop_element: 'container',
12+
max_file_size: '100mb',
13+
flash_swf_url: 'js/plupload/Moxie.swf',
14+
dragdrop: true,
15+
chunk_size: '4mb',
16+
uptoken_url: $('#uptoken_url').val(),
17+
domain: $('#domain').val(),
18+
// unique_names: true,
19+
// save_key: true,
20+
// x_vars: {
21+
// 'id': '1234',
22+
// 'time': function(up, file) {
23+
// var time = (new Date()).getTime();
24+
// // do something with 'time'
25+
// return time;
26+
// },
27+
// },
28+
auto_start: true,
29+
init: {
30+
'FilesAdded': function(up, files) {
31+
$('table').show();
32+
$('#success').hide();
33+
plupload.each(files, function(file) {
34+
var progress = new FileProgress(file, 'fsUploadProgress');
35+
progress.setStatus("等待...");
36+
});
37+
},
38+
'BeforeUpload': function(up, file) {
3339
var progress = new FileProgress(file, 'fsUploadProgress');
34-
progress.setStatus("等待...");
35-
});
36-
},
37-
'BeforeUpload': function(up, file) {
38-
var progress = new FileProgress(file, 'fsUploadProgress');
39-
var chunk_size = plupload.parseSize(this.getOption('chunk_size'));
40-
if (up.runtime === 'html5' && chunk_size) {
41-
progress.setChunkProgess(chunk_size);
40+
var chunk_size = plupload.parseSize(this.getOption('chunk_size'));
41+
if (up.runtime === 'html5' && chunk_size) {
42+
progress.setChunkProgess(chunk_size);
43+
}
44+
},
45+
'UploadProgress': function(up, file) {
46+
var progress = new FileProgress(file, 'fsUploadProgress');
47+
var chunk_size = plupload.parseSize(this.getOption('chunk_size'));
48+
progress.setProgress(file.percent + "%", up.total.bytesPerSec, chunk_size);
49+
50+
},
51+
'UploadComplete': function() {
52+
$('#success').show();
53+
},
54+
'FileUploaded': function(up, file, info) {
55+
var progress = new FileProgress(file, 'fsUploadProgress');
56+
progress.setComplete(up, info);
57+
},
58+
'Error': function(up, err, errTip) {
59+
$('table').show();
60+
var progress = new FileProgress(err.file, 'fsUploadProgress');
61+
progress.setError();
62+
progress.setStatus(errTip);
4263
}
43-
},
44-
'UploadProgress': function(up, file) {
45-
var progress = new FileProgress(file, 'fsUploadProgress');
46-
var chunk_size = plupload.parseSize(this.getOption('chunk_size'));
47-
progress.setProgress(file.percent + "%", up.total.bytesPerSec, chunk_size);
48-
49-
},
50-
'UploadComplete': function() {
51-
$('#success').show();
52-
},
53-
'FileUploaded': function(up, file, info) {
54-
var progress = new FileProgress(file, 'fsUploadProgress');
55-
progress.setComplete(up, info);
56-
},
57-
'Error': function(up, err, errTip) {
58-
$('table').show();
59-
var progress = new FileProgress(err.file, 'fsUploadProgress');
60-
progress.setError();
61-
progress.setStatus(errTip);
64+
// ,
65+
// 'Key': function(up, file) {
66+
// var key = "";
67+
// // do something with key
68+
// return key
69+
// }
6270
}
63-
// ,
64-
// 'Key': function(up, file) {
65-
// var key = "";
66-
// // do something with key
67-
// return key
68-
// }
69-
}
70-
});
71-
72-
uploader.bind('FileUploaded', function() {
73-
console.log('hello man,a file is uploaded');
74-
});
71+
});
7572

76-
$(function() {
73+
uploader.bind('FileUploaded', function() {
74+
console.log('hello man,a file is uploaded');
75+
});
7776
$('#container').on(
7877
'dragenter',
7978
function(e) {

demo/server.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ app.configure(function() {
77
app.use(express.static(__dirname + '/'));
88
});
99

10+
app.set('views', __dirname + '/views');
11+
app.engine('html', require('ejs').renderFile);
12+
13+
1014
app.use(function(req, res, next) {
1115
req.headers['if-none-match'] = 'no-match-for-this';
1216
next();
@@ -20,13 +24,15 @@ app.get('/token', function(req, res, next) {
2024
if (token) {
2125
res.json({
2226
uptoken: token
23-
})
27+
});
2428
}
2529
});
2630

2731
app.get('/', function(req, res) {
28-
res.setHeader('Pragma', 'no-cache');
29-
res.sendfile(__dirname + '/index.html')
32+
res.render('index.html', {
33+
domain: config.Domain,
34+
uptoken_url: config.Uptoken_Url
35+
});
3036
});
3137

3238
qiniu.conf.ACCESS_KEY = config.ACCESS_KEY;

demo/index.html renamed to demo/views/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ <h1 class="text-left col-md-12 ">
2525
View Source on Github
2626
</a>
2727
</h1>
28+
<input type="hidden" id="domain" value="<%= domain %>">
29+
<input type="hidden" id="uptoken_url" value="<%= uptoken_url %>">
2830
<ul class="tip col-md-12 text-mute">
2931
<li>
3032
<small>
@@ -91,7 +93,7 @@ <h4 class="modal-title" id="myModalLabel">查看初始化代码</h4>
9193
uptoken_url: '/token', //Ajax请求upToken的Url,**强烈建议设置**(服务端提供)
9294
// uptoken : '<Your upload token>', //若未指定uptoken_url,则必须指定 uptoken ,uptoken由其他程序生成
9395
// unique_names: true, // 默认 false,key为文件名。若开启该选项,SDK为自动生成上传成功后的key(文件名)。
94-
// save_key: true, // 默认 false。若在服务端生成uptoken的上传策略中指定了 `sava_key`,则开启,SDK会忽略对key的处理
96+
// save_key: true, // 默认 false。若在服务端生成uptoken的上传策略中指定了 `sava_key`,则开启,SDK会忽略对key的处理
9597
domain: 'http://qiniu-plupload.qiniudn.com/', //bucket 域名,下载资源时用到,**必需**
9698
container: 'container', //上传区域DOM ID,默认是browser_button的父元素,
9799
max_file_size: '100mb', //最大文件体积限制

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
"dependencies": {
99
"express": "~3.4.7",
1010
"qiniu": "~6.1.1"
11+
"ejs": "~1.0.0"
1112
}
1213
}

0 commit comments

Comments
 (0)