Skip to content

Commit 5114b2a

Browse files
committed
Merge pull request #14 from qiniupd/8351_add_x_val_feature
8351 add x val feature again
2 parents dc2b7f0 + b435e2d commit 5114b2a

File tree

4 files changed

+38
-10
lines changed

4 files changed

+38
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ qiniu-js-sdk
7777
// 'time' : function(up,file) {
7878
// var time = (new Date()).getTime();
7979
// do something with 'time'
80-
// returnt time;
80+
// return time;
8181
// },
8282
// 'size' : function(up,file) {
8383
// var size = file.size;

demo/js/main.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ var uploader = Qiniu.uploader({
1616
domain: 'http://qiniu-plupload.qiniudn.com/',
1717
// unique_names: true,
1818
// 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+
// },
1927
auto_start: true,
2028
init: {
2129
'FilesAdded': function(up, files) {
@@ -216,4 +224,4 @@ $(function() {
216224
return false;
217225
});
218226

219-
});
227+
});

demo/js/qiniu.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,12 @@ function QiniuJsSDK() {
347347
var x_vars = op.x_vars;
348348
if (x_vars !== undefined && typeof x_vars === 'object') {
349349
for (var x_key in x_vars) {
350-
if (x_vars.hasOwnProperty(x_key) && typeof x_vars[x_key] === 'function') {
351-
multipart_params_obj['x:' + x_key] = x_vars[x_key](up, file);
350+
if (x_vars.hasOwnProperty(x_key)) {
351+
if (typeof x_vars[x_key] === 'function') {
352+
multipart_params_obj['x:' + x_key] = x_vars[x_key](up, file);
353+
} else if (typeof x_vars[x_key] !== 'object') {
354+
multipart_params_obj['x:' + x_key] = x_vars[x_key];
355+
}
352356
}
353357
}
354358
}
@@ -496,11 +500,16 @@ function QiniuJsSDK() {
496500
}
497501

498502
var x_vars = op.x_vars,
503+
x_val = '',
499504
x_vars_url = '';
500505
if (x_vars !== undefined && typeof x_vars === 'object') {
501506
for (var x_key in x_vars) {
502-
if (x_vars.hasOwnProperty(x_key) && typeof x_vars[x_key] === 'function') {
503-
var x_val = that.URLSafeBase64Encode(x_vars[x_key](up, file));
507+
if (x_vars.hasOwnProperty(x_key)) {
508+
if (typeof x_vars[x_key] === 'function') {
509+
x_val = that.URLSafeBase64Encode(x_vars[x_key](up, file));
510+
} else if (typeof x_vars[x_key] !== 'object') {
511+
x_val = that.URLSafeBase64Encode(x_vars[x_key]);
512+
}
504513
x_vars_url += '/x:' + x_key + '/' + x_val;
505514
}
506515
}
@@ -516,6 +525,7 @@ function QiniuJsSDK() {
516525
if (ajax.readyState === 4) {
517526
if (ajax.status === 200) {
518527
var info = ajax.responseText;
528+
519529
if (FileUploaded_Handler) {
520530
FileUploaded_Handler(up, file, info);
521531
}

src/qiniu.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,12 @@ function QiniuJsSDK() {
347347
var x_vars = op.x_vars;
348348
if (x_vars !== undefined && typeof x_vars === 'object') {
349349
for (var x_key in x_vars) {
350-
if (x_vars.hasOwnProperty(x_key) && typeof x_vars[x_key] === 'function') {
351-
multipart_params_obj['x:' + x_key] = x_vars[x_key](up, file);
350+
if (x_vars.hasOwnProperty(x_key)) {
351+
if (typeof x_vars[x_key] === 'function') {
352+
multipart_params_obj['x:' + x_key] = x_vars[x_key](up, file);
353+
} else if (typeof x_vars[x_key] !== 'object') {
354+
multipart_params_obj['x:' + x_key] = x_vars[x_key];
355+
}
352356
}
353357
}
354358
}
@@ -496,11 +500,16 @@ function QiniuJsSDK() {
496500
}
497501

498502
var x_vars = op.x_vars,
503+
x_val = '',
499504
x_vars_url = '';
500505
if (x_vars !== undefined && typeof x_vars === 'object') {
501506
for (var x_key in x_vars) {
502-
if (x_vars.hasOwnProperty(x_key) && typeof x_vars[x_key] === 'function') {
503-
var x_val = that.URLSafeBase64Encode(x_vars[x_key](up, file));
507+
if (x_vars.hasOwnProperty(x_key)) {
508+
if (typeof x_vars[x_key] === 'function') {
509+
x_val = that.URLSafeBase64Encode(x_vars[x_key](up, file));
510+
} else if (typeof x_vars[x_key] !== 'object') {
511+
x_val = that.URLSafeBase64Encode(x_vars[x_key]);
512+
}
504513
x_vars_url += '/x:' + x_key + '/' + x_val;
505514
}
506515
}
@@ -516,6 +525,7 @@ function QiniuJsSDK() {
516525
if (ajax.readyState === 4) {
517526
if (ajax.status === 200) {
518527
var info = ajax.responseText;
528+
519529
if (FileUploaded_Handler) {
520530
FileUploaded_Handler(up, file, info);
521531
}

0 commit comments

Comments
 (0)