Skip to content

fix:uploadFIle容错处理 #114

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 6 commits into from
Nov 9, 2021
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cos-nodejs-sdk-v5",
"version": "2.10.6",
"version": "2.10.7",
"description": "cos nodejs sdk v5",
"main": "index.js",
"types": "index.d.ts",
Expand Down
8 changes: 5 additions & 3 deletions sdk/advance.js
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,9 @@ function uploadFile(params, callback) {
var taskList = [];

fs.stat(params.FilePath, function (err, stat) {
if (err) {
return callback(err);
}

var isDir = stat.isDirectory();
var FileSize = params.ContentLength = stat.size || 0;
Expand Down Expand Up @@ -871,9 +874,8 @@ function uploadFiles(params, callback) {
var count = params.files.length;
util.each(params.files, function (fileParams, index) {
fs.stat(fileParams.FilePath, function (err, stat) {

var isDir = stat.isDirectory();
var FileSize = fileParams.ContentLength = stat.size || 0;
var isDir = stat ? stat.isDirectory() : false;
var FileSize = fileParams.ContentLength = stat ? stat.size : 0;
var fileInfo = {Index: index, TaskId: ''};

// 更新文件总大小
Expand Down
9 changes: 6 additions & 3 deletions sdk/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,12 @@ var md5 = function (str, encoding) {
// 获取文件分片
var fileSlice = function (FilePath, start, end, callback) {
if (FilePath) {
var readStream = fs.createReadStream(FilePath, {start: start, end: end - 1});
readStream.isSdkCreated = true;
callback(readStream);
try {
var readStream = fs.createReadStream(FilePath, {start: start, end: end - 1});
readStream.isSdkCreated = true;
callback(readStream);
} catch(e) {
}
} else {
callback(null);
}
Expand Down