xbc30 / large-file-upload Goto Github PK
View Code? Open in Web Editor NEWNodejs large file segment upload, resumable upload. Nodejs大文件分片上传、断点续传
Nodejs large file segment upload, resumable upload. Nodejs大文件分片上传、断点续传
Error: Request failed with status code 413
at createError (webpack-internal:///./node_modules/_axios@0.19.2@axios/lib/core/createError.js:16:15)
at settle (webpack-internal:///./node_modules/_axios@0.19.2@axios/lib/core/settle.js:17:12)
at XMLHttpRequest.handleLoad (webpack-internal:///./node_modules/_axios@0.19.2@axios/lib/adapters/xhr.js:61:7)
From previous event:
at _callee5$ (webpack-internal:///./node_modules/_cache-loader@4.1.0@cache-loader/dist/cjs.js?!./node_modules/_babel-loader@8.2.2@babel-loader/lib/index.js!./node_modules/_cache-loader@4.1.0@cache-loader/dist/cjs.js?!./node_modules/_vue-loader@15.9.6@vue-loader/lib/index.js?!./src/components/upload.vue?vue&type=script&lang=js&:523:66)
at tryCatch (webpack-internal:///./node_modules/_regenerator-runtime@0.13.7@regenerator-runtime/runtime.js:63:40)
at Generator.invoke [as invoke] (webpack-internal:///./node_modules/regenerator-runtime@0.13.7@regenerator-runtime/runtime.js:293:22)
at Generator.eval [as next] (webpack-internal:///./node_modules/regenerator-runtime@0.13.7@regenerator-runtime/runtime.js:118:21)
at asyncGeneratorStep (webpack-internal:///./node_modules/@[email protected]@@babel/runtime/helpers/esm/asyncToGenerator.js:9:24)
at next (webpack-internal:///./node_modules/@[email protected]@@babel/runtime/helpers/esm/asyncToGenerator.js:31:9)
at eval (webpack-internal:///./node_modules/@[email protected]@@babel/runtime/helpers/esm/asyncToGenerator.js:38:7)
at new Promise ()
at eval (webpack-internal:///./node_modules/@[email protected]@@babel/runtime/helpers/esm/asyncToGenerator.js:27:12)
at VueComponent.buildFormDataToSend (webpack-internal:///./node_modules/_cache-loader@4.1.0@cache-loader/dist/cjs.js?!./node_modules/_babel-loader@8.2.2@babel-loader/lib/index.js!./node_modules/_cache-loader@4.1.0@cache-loader/dist/cjs.js?!./node_modules/_vue-loader@15.9.6@vue-loader/lib/index.js?!./src/components/upload.vue?vue&type=script&lang=js&:595:10)
at _callee2$ (webpack-internal:///./node_modules/_cache-loader@4.1.0@cache-loader/dist/cjs.js?!./node_modules/_babel-loader@8.2.2@babel-loader/lib/index.js!./node_modules/_cache-loader@4.1.0@cache-loader/dist/cjs.js?!./node_modules/_vue-loader@15.9.6@vue-loader/lib/index.js?!./src/components/upload.vue?vue&type=script&lang=js&:392:29)
at tryCatch (webpack-internal:///./node_modules/_regenerator-runtime@0.13.7@regenerator-runtime/runtime.js:63:40)
at Generator.invoke [as _invoke] (webpack-internal:///./node_modules/_regenerator-runtime@0.13.7@regenerator-runtime/runtime.js:293:22)
at Generator.eval [as next] (webpack-internal:///./node_modules/regenerator-runtime@0.13.7@regenerator-runtime/runtime.js:118:21)
at asyncGeneratorStep (webpack-internal:///./node_modules/@[email protected]@@babel/runtime/helpers/esm/asyncToGenerator.js:9:24)
2020-11-04 15:31:43,372 ERROR 2124 nodejs.AppWorkerDiedError: [master] app_worker#1:7892 died (code: 1, signal: null, suicide: false, state: dead), current workers: []
at Master.onAppExit (D:\其他\server\node_modules\egg-cluster\lib\master.js:510:21)
at Master.emit (events.js:311:20)
at Messenger.sendToMaster (D:\其他\server\node_modules\egg-cluster\lib\utils\messenger.js:137:17)
at Messenger.send (D:\其他\server\node_modules\egg-cluster\lib\utils\messenger.js:102:12)
at EventEmitter. (D:\其他\server\node_modules\egg-cluster\lib\master.js:353:22)
at EventEmitter.emit (events.js:323:22)
at ChildProcess. (internal/cluster/master.js:193:13)
at Object.onceWrapper (events.js:418:26)
at ChildProcess.emit (events.js:311:20)
at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
name: "AppWorkerDiedError"
pid: 2124
hostname: DESKTOP-0V6F2MO
2020-11-04 15:31:43,392 ERROR 2124 [master] app_worker#1:7892 start fail, exiting
with code:1
2020-11-04 15:31:43,393 ERROR 2124 [master] exit with code:1
// 构建Socket.IO Blob数据并请求,最后请求合并分片
async buildBlobData(chunkCount, file, hash, res) {
const that = this;
const blobData = [];
for (let i = 0; i < chunkCount; i++) {
if (
res.type == 0 ||
(res.type == 1 &&
res.index &&
res.index.length > 0 &&
!res.index.includes(i.toString()))
) {
const start = i * that.chunkSize;
const end = Math.min(file.size, start + that.chunkSize);
const blobItem = Object.create({});
blobItem.file = blobSlice.call(file, start, end);
blobItem.name = file.name;
blobItem.total = chunkCount;
blobItem.chunkSize = that.chunkSize;
blobItem.index = i;
blobItem.size = file.size;
blobItem.hash = hash;
blobData.push(blobItem);
}
}
for (let item of blobData) {
await that.socket.emit("upload", item);
}
},
在测试中发现,node合并多个分片后无法使用。比如分片大于5个的视频,合并后,视频后面无法播放了。
错误原因是:
let chunks = fs.readdirSync(chunksPath);
chunks 中的顺序是错误的,造成合并出来不能播放.
let chunks = fs.readdirSync(chunksPath);
-------增加下面排好顺序即可---------
chunks = chunks.sort(function (a, b) {
var _a = a.split('-');
var _b = b.split('-');
var _na = parseInt(_a[1]);
var _nb = parseInt(_b[1]);
return _na - _nb;
})
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.