@@ -221,13 +221,14 @@ function uploadBuf(body, key, uptoken) {
221221 //extra.crc32 = crc32;
222222 //extra.checkCrc = checkCrc;
223223
224- io.put(uptoken, key, body, extra, function(ret) {
225- if(ret.code === 200 ) {
224+ io.put(uptoken, key, body, extra, function(err, ret) {
225+ if (!err ) {
226226 // 上传成功, 处理返回值
227- // ret.data.key & ret.data.hash
227+ console.log(ret.key, ret.hash);
228+ // ret.key & ret.hash
228229 } else {
229230 // 上传失败, 处理返回代码
230- // ret.code
231+ console.log(err)
231232 // http://docs.qiniu.com/api/put.html#error-code
232233 }
233234 });
@@ -244,13 +245,14 @@ function uploadFile(localFile, key, uptoken) {
244245 //extra.crc32 = crc32;
245246 //extra.checkCrc = checkCrc;
246247
247- io.putFile(uptoken, key, localFile, extra, function(ret) {
248- if(ret.code === 200 ) {
248+ io.putFile(uptoken, key, localFile, extra, function(err, ret) {
249+ if(!err ) {
249250 // 上传成功, 处理返回值
250- // ret.data.key & ret.data.hash
251+ console.log(ret.key, ret.hash);
252+ // ret.key & ret.hash
251253 } else {
252254 // 上传失败, 处理返回代码
253- // ret.code
255+ console.log(err);
254256 // http://docs.qiniu.com/api/put.html#error-code
255257 }
256258 });
@@ -318,12 +320,12 @@ qiniu.conf.SECRET_KEY = '<Your Secret Key>';
318320
319321``` {javascript}
320322var client = new qiniu.rs.Client();
321- client.stat(bucketName, key, function(ret) {
322- if (ret.code === 200 ) {
323- // process
324- // ret.data has keys (hash, fsize, putTime, mimeType)
323+ client.stat(bucketName, key, function(err, ret) {
324+ if (!err ) {
325+ // ok
326+ // ret has keys (hash, fsize, putTime, mimeType)
325327 } else {
326- // something error, process ret.code
328+ console.log(err);
327329 // http://docs.qiniu.com/api/file-handle.html#error-code
328330 }
329331});
@@ -335,11 +337,11 @@ client.stat(bucketName, key, function(ret) {
335337
336338``` {javascript}
337339var client = new qiniu.rs.Client();
338- client.remove(bucketName, key, function(ret) {
339- if (ret.code === 200 ) {
340+ client.remove(bucketName, key, function(err, ret) {
341+ if (!err ) {
340342 // ok
341343 } else {
342- // something error, process ret.code
344+ console.log(err);
343345 // http://docs.qiniu.com/api/file-handle.html#error-code
344346 }
345347})
@@ -351,23 +353,23 @@ client.remove(bucketName, key, function(ret) {
351353
352354``` {javascript}
353355var client = new qiniu.rs.Client();
354- client.copy(bucketSrc, keySrc, bucketDestm keyDest, function(ret) {
355- if (ret.code === 200 ) {
356+ client.copy(bucketSrc, keySrc, bucketDest, keyDest, function(err, ret) {
357+ if (!err ) {
356358 // ok
357359 } else {
358- // something error, process ret.code
360+ console.log(err);
359361 // http://docs.qiniu.com/api/file-handle.html#error-code
360362 }
361363});
362364```
363365
364366``` {javascript}
365367var client = new qiniu.rs.Client();
366- client.move(bucketSrc, keySrc, bucketDestm keyDest, function(ret) {
367- if (ret.code === 200 ) {
368+ client.move(bucketSrc, keySrc, bucketDest, keyDest, function(err, ret) {
369+ if (!err ) {
368370 // ok
369371 } else {
370- // something error, process ret.code
372+ console.log(err);
371373 // http://docs.qiniu.com/api/file-handle.html#error-code
372374 }
373375});
@@ -377,7 +379,14 @@ client.move(bucketSrc, keySrc, bucketDestm keyDest, function(ret) {
377379
378380#### 批量操作
379381
380- 当您需要一次性进行多个操作时, 可以使用批量操作。
382+ 当您需要一次性进行多个操作时, 可以使用批量操作。
383+ 批量操作的几个函数中,当返回值` err ` 为` null ` 的时候,有两种情况:
384+
385+ 1 . 批量操作的所有操作都成功
386+ 2 . 批量操作仅仅部分成功
387+
388+ 因此在返回成功的时候还需要检查各个子项目的返回值(详细见各个示例)。
389+ 注意:批量操作不是对单个文件操作的包装,而是有独立的接口。
381390
382391#### 批量获取文件信息
383392
@@ -386,13 +395,20 @@ var path0 = new qiniu.rs.EntryPath(bucketName, key0);
386395var path1 = new qiniu.rs.EntryPath(bucketName, key1);
387396var path2 = new qiniu.rs.EntryPath(bucketName, key2);
388397var client = new qiniu.rs.Client();
389- client.batchStat([path0, path1, path2], function(ret) {
390- if (ret.code === 200) {
391- // ok, parse ret.data
392- // each item in ret.data has keys (code, data)
393- // ret.data[i].data has keys (hash, fsize, putTime, mimeType)
398+
399+ client.batchStat([path0, path1, path2], function(err, ret) {
400+ if (!err) {
401+ for (i in ret) {
402+ if (ret[i].code === 200) {
403+ //ok, ret[i].data has keys (hash, fsize, putTime, mimeType)
404+ } else {
405+ // parse error code
406+ console.log(ret[i].code, ret[i].data);
407+ // http://docs.qiniu.com/api/file-handle.html#error-code
408+ }
409+ }
394410 } else {
395- // something error, process ret.code
411+ console.log(err);
396412 // http://docs.qiniu.com/api/file-handle.html#error-code
397413 }
398414});
@@ -405,15 +421,24 @@ var pathSrc0 = new qiniu.rs.EntryPath(bucketName, key0);
405421var pathDest0 = new qiniu.rs.EntryPath(bucketName, key1);
406422var pathSrc1 = new qiniu.rs.EntryPath(bucketName, key2);
407423var pathDest1 = new qiniu.rs.EntryPath(bucketName, key3);
424+
408425var pair0 = new qiniu.rs.EntryPathPair(pathSrc0, pathDest0);
409426var pair1 = new qiniu.rs.EntryPathPair(pathSrc1, pathDest1);
427+
410428var client = new qiniu.rs.Client();
411429
412- client.batchCopy([pair0, pair1], function(ret) {
413- if (ret.code === 200) {
414- // ok
430+ client.batchCopy([pair0, pair1], function(err, ret) {
431+ if (!err) {
432+ for (i in ret) {
433+ if (ret[i].code !== 200) {
434+ // parse error code
435+ console.log(ret[i].code, ret[i].data);
436+ // http://docs.qiniu.com/api/file-handle.html#error-code
437+ }
438+ }
439+
415440 } else {
416- // something error, process ret.code
441+ console.log(err);
417442 // http://docs.qiniu.com/api/file-handle.html#error-code
418443 }
419444});
@@ -426,15 +451,23 @@ var pathSrc0 = new qiniu.rs.EntryPath(bucketName, key0);
426451var pathDest0 = new qiniu.rs.EntryPath(bucketName, key1);
427452var pathSrc1 = new qiniu.rs.EntryPath(bucketName, key2);
428453var pathDest1 = new qiniu.rs.EntryPath(bucketName, key3);
454+
429455var pair0 = new qiniu.rs.EntryPathPair(pathSrc0, pathDest0);
430456var pair1 = new qiniu.rs.EntryPathPair(pathSrc1, pathDest1);
457+
431458var client = new qiniu.rs.Client();
432459
433- client.batchMove([pair0, pair1], function(ret) {
434- if (ret.code === 200) {
435- // ok
460+ client.batchMove([pair0, pair1], function(err, ret) {
461+ if (!err) {
462+ for (i in ret) {
463+ if (ret[i] !== 200) {
464+ // parse error code
465+ console.log(ret[i].code, ret[i].data);
466+ // http://docs.qiniu.com/api/file-handle.html#error-code
467+ }
468+ }
436469 } else {
437- // something error, process ret.code
470+ console.log(err);
438471 // http://docs.qiniu.com/api/file-handle.html#error-code
439472 }
440473});
@@ -446,13 +479,20 @@ client.batchMove([pair0, pair1], function(ret) {
446479var path0 = new qiniu.rs.EntryPath(bucketName, key0);
447480var path1 = new qiniu.rs.EntryPath(bucketName, key1);
448481var path2 = new qiniu.rs.EntryPath(bucketName, key2);
482+
449483var client = new qiniu.rs.Client();
450484
451- client.batchDelete([path0, path1, path2], function(ret) {
452- if (ret.code === 200) {
453- // ok
485+ client.batchDelete([path0, path1, path2], function(err, ret) {
486+ if (!err) {
487+ for (i in ret) {
488+ if (ret[i].code !== 200) {
489+ // parse error code
490+ console.log(ret[i].code, ret[i].data);
491+ // http://docs.qiniu.com/api/file-handle.html#error-code
492+ }
493+ }
454494 } else {
455- // something error, process ret.code
495+ console.log(err);
456496 // http://docs.qiniu.com/api/file-handle.html#error-code
457497 }
458498});
@@ -470,11 +510,11 @@ client.batchDelete([path0, path1, path2], function(ret) {
470510qiniu.conf.ACCESS_KEY = '<Your Access Key>';
471511qiniu.conf.SECRET_KEY = '<Your Secret Key>';
472512
473- qiniu.rsf.listPrefix(bucketname, prefix, marker, limit, function(ret) {
474- if(ret.code === 200 ) {
513+ qiniu.rsf.listPrefix(bucketname, prefix, marker, limit, function(err, ret) {
514+ if (!err ) {
475515 // process ret.data.marker & ret.data.items
476516 } else {
477- // something error, see ret.code according to
517+ console.log(err)
478518 // http://docs.qiniu.com/api/file-handle.html#list
479519 }
480520});
0 commit comments