Skip to content

Commit

Permalink
add x:val feature in js-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
SunLn committed Apr 30, 2014
1 parent 49ebd2e commit 1971aa9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
24 changes: 22 additions & 2 deletions demo/js/qiniu.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,16 @@ function QiniuJsSDK() {
};
}

var x_vars = op.x_vars;
if (x_vars !== undefined && typeof x_vars === 'object') {
for (var x_key in x_vars) {
if (x_vars.hasOwnProperty(x_key) && typeof x_vars[x_key] === 'function') {
multipart_params_obj['x:' + x_key] = x_vars[x_key](up, file);
}
}
}


up.setOption({
'url': 'http://up.qiniu.com/',
'multipart': true,
Expand Down Expand Up @@ -480,13 +490,23 @@ function QiniuJsSDK() {
ctx = ctx ? ctx : res.ctx;
if (ctx) {
var key = '';

if (!op.save_key) {
key = getFileKey(up, file, that.key_handler);
key = key ? '/key/' + that.URLSafeBase64Encode(key) : '';
}

var url = 'http://up.qiniu.com/mkfile/' + file.size + key;
var x_vars = op.x_vars,
x_vars_url = '';
if (x_vars !== undefined && typeof x_vars === 'object') {
for (var x_key in x_vars) {
if (x_vars.hasOwnProperty(x_key) && typeof x_vars[x_key] === 'function') {
var x_val = that.URLSafeBase64Encode(x_vars[x_key](up, file));
x_vars_url += '/x:' + x_key + '/' + x_val;
}
}
}

var url = 'http://up.qiniu.com/mkfile/' + file.size + key + x_vars_url;
var ajax = that.createAjax();
ajax.open('POST', url, true);
ajax.setRequestHeader('Content-Type', 'text/plain;charset=UTF-8');
Expand Down
24 changes: 22 additions & 2 deletions src/qiniu.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,16 @@ function QiniuJsSDK() {
};
}

var x_vars = op.x_vars;
if (x_vars !== undefined && typeof x_vars === 'object') {
for (var x_key in x_vars) {
if (x_vars.hasOwnProperty(x_key) && typeof x_vars[x_key] === 'function') {
multipart_params_obj['x:' + x_key] = x_vars[x_key](up, file);
}
}
}


up.setOption({
'url': 'http://up.qiniu.com/',
'multipart': true,
Expand Down Expand Up @@ -480,13 +490,23 @@ function QiniuJsSDK() {
ctx = ctx ? ctx : res.ctx;
if (ctx) {
var key = '';

if (!op.save_key) {
key = getFileKey(up, file, that.key_handler);
key = key ? '/key/' + that.URLSafeBase64Encode(key) : '';
}

var url = 'http://up.qiniu.com/mkfile/' + file.size + key;
var x_vars = op.x_vars,
x_vars_url = '';
if (x_vars !== undefined && typeof x_vars === 'object') {
for (var x_key in x_vars) {
if (x_vars.hasOwnProperty(x_key) && typeof x_vars[x_key] === 'function') {
var x_val = that.URLSafeBase64Encode(x_vars[x_key](up, file));
x_vars_url += '/x:' + x_key + '/' + x_val;
}
}
}

var url = 'http://up.qiniu.com/mkfile/' + file.size + key + x_vars_url;
var ajax = that.createAjax();
ajax.open('POST', url, true);
ajax.setRequestHeader('Content-Type', 'text/plain;charset=UTF-8');
Expand Down

0 comments on commit 1971aa9

Please sign in to comment.