Skip to content

add x:val feature in js-sdk #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 30, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,20 @@ qiniu-js-sdk
dragdrop: true, //开启可拖曳上传
drop_element: 'container', //拖曳上传区域元素的ID,拖曳文件或文件夹后可触发上传
chunk_size: '4mb', //分块上传时,每片的体积
auto_start: true, //选择文件后自动上传,若关闭需要自己绑定事件触发上传
auto_start: true, //选择文件后自动上传,若关闭需要自己绑定事件触发上传,
//x_vals : {
// 自定义变量,参考http://developer.qiniu.com/docs/v6/api/overview/up/response/vars.html
// 'time' : function(up,file) {
// var time = (new Date()).getTime();
// do something with 'time'
// returnt time;
// },
// 'size' : function(up,file) {
// var size = file.size;
// do something with 'size'
// return size;
// }
//},
init: {
'FilesAdded': function(up, files) {
plupload.each(files, function(file) {
Expand Down
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