Skip to content

Commit c7817bb

Browse files
authored
Merge pull request #114 from livehigh/master
fix:uploadFIle容错处理
2 parents d4015d5 + d8663a2 commit c7817bb

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cos-nodejs-sdk-v5",
3-
"version": "2.10.6",
3+
"version": "2.10.7",
44
"description": "cos nodejs sdk v5",
55
"main": "index.js",
66
"types": "index.d.ts",

sdk/advance.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,9 @@ function uploadFile(params, callback) {
795795
var taskList = [];
796796

797797
fs.stat(params.FilePath, function (err, stat) {
798+
if (err) {
799+
return callback(err);
800+
}
798801

799802
var isDir = stat.isDirectory();
800803
var FileSize = params.ContentLength = stat.size || 0;
@@ -871,9 +874,8 @@ function uploadFiles(params, callback) {
871874
var count = params.files.length;
872875
util.each(params.files, function (fileParams, index) {
873876
fs.stat(fileParams.FilePath, function (err, stat) {
874-
875-
var isDir = stat.isDirectory();
876-
var FileSize = fileParams.ContentLength = stat.size || 0;
877+
var isDir = stat ? stat.isDirectory() : false;
878+
var FileSize = fileParams.ContentLength = stat ? stat.size : 0;
877879
var fileInfo = {Index: index, TaskId: ''};
878880

879881
// 更新文件总大小

sdk/util.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,12 @@ var md5 = function (str, encoding) {
176176
// 获取文件分片
177177
var fileSlice = function (FilePath, start, end, callback) {
178178
if (FilePath) {
179-
var readStream = fs.createReadStream(FilePath, {start: start, end: end - 1});
180-
readStream.isSdkCreated = true;
181-
callback(readStream);
179+
try {
180+
var readStream = fs.createReadStream(FilePath, {start: start, end: end - 1});
181+
readStream.isSdkCreated = true;
182+
callback(readStream);
183+
} catch(e) {
184+
}
182185
} else {
183186
callback(null);
184187
}

0 commit comments

Comments
 (0)