Skip to content

Commit 0369cee

Browse files
authored
Update resume.js
在小于100kb(大概值)的文件上传中,rsStream 的 ‘data’和‘end’会先后触发. 导致mkfileReq方法中finishedCtxList为空,上传文件失败. 添加了一个标记位,如果文件已经读取结束.直接在mkblkReq的callback调用mkfileReq.
1 parent 81e37cb commit 0369cee

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

qiniu/storage/resume.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ function putReq(config, uploadToken, key, rsStream, rsStreamLen, putExtra,
143143
} catch (e) {}
144144
}
145145

146+
var isend = rsStream._readableState.ended;
147+
146148
//check when to mkblk
147149
rsStream.on('data', function(chunk) {
148150
readLen += chunk.length;
@@ -179,6 +181,9 @@ function putReq(config, uploadToken, key, rsStream, rsStreamLen, putExtra,
179181
}
180182

181183
rsStream.resume();
184+
if (isend) {
185+
mkfileReq(upDomain, uploadToken, fileSize, finishedCtxList, key, putExtra, callbackFunc);
186+
}
182187
}
183188
});
184189
}
@@ -188,8 +193,10 @@ function putReq(config, uploadToken, key, rsStream, rsStreamLen, putExtra,
188193
//check when to mkfile
189194
rsStream.on('end', function() {
190195
//console.log("end");
191-
mkfileReq(upDomain, uploadToken, fileSize, finishedCtxList, key,
196+
if (!isend) {
197+
mkfileReq(upDomain, uploadToken, fileSize, finishedCtxList, key,
192198
putExtra, callbackFunc);
199+
}
193200
});
194201
}
195202

0 commit comments

Comments
 (0)