Skip to content

Commit 1971aa9

Browse files
author
SunLn
committed
add x:val feature in js-sdk
1 parent 49ebd2e commit 1971aa9

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

demo/js/qiniu.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,16 @@ function QiniuJsSDK() {
344344
};
345345
}
346346

347+
var x_vars = op.x_vars;
348+
if (x_vars !== undefined && typeof x_vars === 'object') {
349+
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);
352+
}
353+
}
354+
}
355+
356+
347357
up.setOption({
348358
'url': 'http://up.qiniu.com/',
349359
'multipart': true,
@@ -480,13 +490,23 @@ function QiniuJsSDK() {
480490
ctx = ctx ? ctx : res.ctx;
481491
if (ctx) {
482492
var key = '';
483-
484493
if (!op.save_key) {
485494
key = getFileKey(up, file, that.key_handler);
486495
key = key ? '/key/' + that.URLSafeBase64Encode(key) : '';
487496
}
488497

489-
var url = 'http://up.qiniu.com/mkfile/' + file.size + key;
498+
var x_vars = op.x_vars,
499+
x_vars_url = '';
500+
if (x_vars !== undefined && typeof x_vars === 'object') {
501+
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));
504+
x_vars_url += '/x:' + x_key + '/' + x_val;
505+
}
506+
}
507+
}
508+
509+
var url = 'http://up.qiniu.com/mkfile/' + file.size + key + x_vars_url;
490510
var ajax = that.createAjax();
491511
ajax.open('POST', url, true);
492512
ajax.setRequestHeader('Content-Type', 'text/plain;charset=UTF-8');

src/qiniu.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,16 @@ function QiniuJsSDK() {
344344
};
345345
}
346346

347+
var x_vars = op.x_vars;
348+
if (x_vars !== undefined && typeof x_vars === 'object') {
349+
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);
352+
}
353+
}
354+
}
355+
356+
347357
up.setOption({
348358
'url': 'http://up.qiniu.com/',
349359
'multipart': true,
@@ -480,13 +490,23 @@ function QiniuJsSDK() {
480490
ctx = ctx ? ctx : res.ctx;
481491
if (ctx) {
482492
var key = '';
483-
484493
if (!op.save_key) {
485494
key = getFileKey(up, file, that.key_handler);
486495
key = key ? '/key/' + that.URLSafeBase64Encode(key) : '';
487496
}
488497

489-
var url = 'http://up.qiniu.com/mkfile/' + file.size + key;
498+
var x_vars = op.x_vars,
499+
x_vars_url = '';
500+
if (x_vars !== undefined && typeof x_vars === 'object') {
501+
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));
504+
x_vars_url += '/x:' + x_key + '/' + x_val;
505+
}
506+
}
507+
}
508+
509+
var url = 'http://up.qiniu.com/mkfile/' + file.size + key + x_vars_url;
490510
var ajax = that.createAjax();
491511
ajax.open('POST', url, true);
492512
ajax.setRequestHeader('Content-Type', 'text/plain;charset=UTF-8');

0 commit comments

Comments
 (0)