{"id":15374,"date":"2024-05-27T08:54:05","date_gmt":"2024-05-27T00:54:05","guid":{"rendered":"https:\/\/92it.top\/?p=15374"},"modified":"2024-05-27T08:54:05","modified_gmt":"2024-05-27T00:54:05","slug":"%e5%a4%a7%e6%96%87%e4%bb%b6%e5%88%87%e7%89%87%e4%b8%8a%e4%bc%a0%ef%bc%8c%e5%85%a8%e7%bd%91%e6%9c%80%e7%ae%80%e5%8d%95%e7%9a%84%e5%ae%9e%e7%8e%b0%e6%b2%a1%e6%9c%89%e4%b9%8b%e4%b8%80","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=15374","title":{"rendered":"\u5927\u6587\u4ef6\u5207\u7247\u4e0a\u4f20\uff0c\u5168\u7f51\u6700\u7b80\u5355\u7684\u5b9e\u73b0\u6ca1\u6709\u4e4b\u4e00"},"content":{"rendered":"\n<p>\u674e\u5c0f\u840c\u540c\u5b66\u7ecf\u8fc7\u4e0a\u6b21\u9762\u8bd5\u5931\u8d25\u540e\uff0c\u52aa\u529b\u63d0\u5347\u81ea\u5df1\u6280\u672f\uff0c\u7ec8\u4e8e\u5165\u804c\u4e00\u5bb6\u8f6f\u4ef6\u516c\u53f8\u3002\u516c\u53f8Leader\u7ed9\u5c0f\u840c\u5206\u914d\u4e86\u4e00\u4e2a\u4e0a\u4f20\u89c6\u9891\u6587\u4ef6\u4efb\u52a1\uff0c\u8981\u6c42\u652f\u6301\u5207\u7247\u4e0a\u4f20\uff0c\u65ad\u70b9\u7eed\u4f20\uff0c\u79d2\u4f20\u529f\u80fd\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"383\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-162-1024x383.png\" alt=\"\" class=\"wp-image-15376\" style=\"width:536px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-162-1024x383.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-162-300x112.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-162-768x287.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-162-830x310.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-162-230x86.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-162-350x131.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-162-480x180.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-162.png 1342w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u5c0f\u840c\u53ea\u505a\u8fc7\u57fa\u7840\u7684\u56fe\u7247\u6587\u4ef6\u4e0a\u4f20\uff0c\u5bf9\u4e8e\u5927\u6587\u4ef6\u5207\u7247\u4e0a\u4f20\u7ecf\u9a8c\u4e0d\u591f\uff0c\u4f46\u8fd9\u96be\u4e0d\u5230\u5c0f\u840c\uff0c\u8c01\u53eb\u548b\u662f\u7a0b\u5e8f\u5458\u5462\uff0c\u5b66\u4e60\u662f\u6211\u4eec\u7684\u7b2c\u4e00\u751f\u4ea7\u529b\u3002\u5c0f\u840c\u9996\u5148\u67e5\u9605\u4e92\u8054\u7f51\uff0c\u95ee\u4e86\u95ee\u767e\u8001\u5e08\uff0c\u63a5\u7740\u5199\u4e86\u4e2a\u5927\u6587\u4ef6\u5207\u7247\u4e0a\u4f20Demo\uff0c\u8fd9\u4e2aDemo\u5305\u542b\u4e24\u4e2a\u6587\u4ef6\uff0c\u4e00\u4e2a\u540e\u7aef\u6587\u4ef6app.js\uff0c\u5b9e\u73b0\u4e86\u63a5\u6536\u4e0a\u4f20\u6587\u4ef6\uff0c\u5408\u5e76\u6587\u4ef6\u548c\u68c0\u9a8c\u6587\u4ef6\u529f\u80fd\u3002\u53e6\u4e00\u4e2a\u662f\u524d\u7aef\u6587\u4ef6upload-1.html\uff0c\u8d1f\u8d23\u5b9e\u73b0\u754c\u9762\u3002<\/p>\n\n\n\n<p>\u8fd0\u884c\u6548\u679c\u5982\u4e0b\u56fe\uff0c\u4e0b\u9762\u6211\u4eec\u5c31\u6765\u770b\u4e0b\u5c0f\u840c\u7684\u5927\u6587\u4ef6\u5207\u7247\u4e0a\u4f20\u662f\u5982\u4f55\u5b9e\u73b0\u7684\u3002<\/p>\n\n\n\n<p><strong>01 \u5927\u6587\u4ef6\u5207\u7247\u4e0a\u4f20\u524d\u7aef\u5b9e\u73b0<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u5927\u6587\u4ef6\u5207\u7247\u4e0a\u4f20\u6700\u5927\u7684\u597d\u5904\u662f\u9632\u6b62\u7f51\u7edc\u4e0d\u597d\u7684\u60c5\u51b5\u4e0b\u6587\u4ef6\u4e0a\u4f20\u4e00\u534a\u6302\u6389\uff0c\u4e0b\u6b21\u5f97\u5168\u90e8\u91cd\u65b0\u4e0a\u4f20\u3002<\/p>\n\n\n\n<p>\u5b9e\u73b0\u601d\u8def\u662f\u5229\u7528\u524d\u7aef\u5c06\u4e00\u4e2a\u5927\u6587\u4ef6\uff0c\u62c6\u5206\u6210\u591a\u4e2a\u5c0f\u6587\u4ef6(\u5206\u7247)\uff1b\u524d\u7aef\u5c06\u62c6\u5206\u597d\u7684\u5c0f\u6587\u4ef6\u4f9d\u6b21\u53d1\u9001\u7ed9\u540e\u7aef(\u6bcf\u4e00\u4e2a\u5c0f\u6587\u4ef6\u5bf9\u5e94\u4e00\u4e2a\u8bf7\u6c42)\uff1b\u540e\u7aef\u6bcf\u63a5\u6536\u5230\u4e00\u4e2a\u5c0f\u6587\u4ef6\uff0c\u5c31\u5c06\u5c0f\u6587\u4ef6\u4fdd\u5b58\u5230\u670d\u52a1\u5668\uff1b\u5f53\u5927\u6587\u4ef6\u7684\u6240\u6709\u5206\u7247\u90fd\u4e0a\u4f20\u5b8c\u6210\u540e\uff0c\u524d\u7aef\u518d\u53d1\u9001\u4e00\u4e2a\u201c\u5408\u5e76\u5206\u7247\u201d\u7684\u8bf7\u6c42\u5230\u540e\u7aef\uff0c\u540e\u7aef\u5bf9\u670d\u52a1\u5668\u4e2d\u6240\u6709\u7684\u5c0f\u6587\u4ef6\u8fdb\u884c\u5408\u5e76\uff0c\u8fd8\u539f\u5b8c\u6574\u7684\u5927\u6587\u4ef6\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"418\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-164-1024x418.png\" alt=\"\" class=\"wp-image-15378\" style=\"width:538px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-164-1024x418.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-164-300x122.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-164-768x313.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-164-830x339.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-164-230x94.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-164-350x143.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-164-480x196.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-164.png 1338w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p><strong>1. \u6587\u4ef6\u5207\u7247<\/strong><\/p>\n\n\n\n<p>\u4f7f\u7528File\u5bf9\u8c61\u7684slice() \u65b9\u6cd5\u5b9e\u73b0,\u00a0\u53c2\u6570\u4e0d\u6e05\u695a\u7684\u67e5\u9605MDN<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"542\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-165-1024x542.png\" alt=\"\" class=\"wp-image-15379\" style=\"width:538px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-165-1024x542.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-165-300x159.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-165-768x407.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-165-830x439.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-165-230x122.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-165-350x185.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-165-480x254.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-165.png 1360w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p><strong>2. \u4e0a\u4f20\u5207\u7247\u6587\u4ef6<\/strong><\/p>\n\n\n\n<p>\u4f7f\u7528FormData\u5bf9\u8c61\u5c01\u88c5\u4e0a\u4f20\u6570\u636e\uff0c\u8fc7\u6ee4\u5df2\u7ecf\u4e0a\u4f20\u8fc7\u7684\u5207\u7247\uff0c\u4f7f\u7528axios\u5e93\u4e0a\u4f20\u5207\u7247\u6587\u4ef6\uff0ccancelToken\u5c5e\u6027\u7ec8\u6b62axios\u7f51\u7edc\u4f20\u8f93\u6682\u505c\u6587\u4ef6\u4e0a\u4f20\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1009\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-167-1024x1009.png\" alt=\"\" class=\"wp-image-15381\" style=\"width:582px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-167-1024x1009.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-167-300x296.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-167-768x757.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-167-830x818.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-167-230x227.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-167-350x345.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-167-480x473.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-167.png 1364w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p><strong>3. \u5408\u5e76\u5207\u7247<\/strong><\/p>\n\n\n\n<p>\u5408\u5e76\u5207\u7247\u529f\u80fd\u4e3b\u8981\u540e\u7aef\u5b9e\u73b0\uff0c\u524d\u7aef\u8d1f\u8d23\u8c03\u7528\u5408\u5e76\u63a5\u53e3<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"483\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-168-1024x483.png\" alt=\"\" class=\"wp-image-15382\" style=\"width:644px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-168-1024x483.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-168-300x142.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-168-768x363.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-168-830x392.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-168-230x109.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-168-350x165.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-168-480x227.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-168.png 1364w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p><strong>4. \u79d2\u4f20\u6587\u4ef6<\/strong><\/p>\n\n\n\n<p>\u79d2\u4f20\u6587\u4ef6\u672c\u8d28\u662f\u68c0\u67e5\u5230\u540e\u7aef\u5df2\u7ecf\u6709\u4e0a\u4f20\u6587\u4ef6\uff0c\u76f4\u63a5\u663e\u793a\u79d2\u4f20\u6210\u529f<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"683\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-169-1024x683.png\" alt=\"\" class=\"wp-image-15383\" style=\"width:622px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-169-1024x683.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-169-300x200.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-169-768x512.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-169-830x554.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-169-230x153.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-169-350x234.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-169-480x320.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-169.png 1358w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p><strong>5. \u5b9e\u73b0\u6d41\u7a0b\u56fe<\/strong><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"774\" height=\"1024\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-171-774x1024.png\" alt=\"\" class=\"wp-image-15385\" style=\"width:504px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-171-774x1024.png 774w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-171-227x300.png 227w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-171-768x1016.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-171-830x1098.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-171-230x304.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-171-350x463.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-171-480x635.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/\u56fe\u7247-171.png 1108w\" sizes=\"(max-width: 774px) 100vw, 774px\" \/><\/figure><\/div>\n\n\n<p><strong>02 \u5927\u6587\u4ef6\u4e0a\u4f20\u540e\u7aef\u5b9e\u73b0<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u540e\u7aef\u91c7\u7528nodejs\u6280\u672f\u5b9e\u73b0\uff0c\u6587\u4ef6\u4e0a\u4f20\u4f7f\u7528multiparty\u00a0\u5e93\uff0c\u6587\u4ef6\u8bfb\u5199\u4f7f\u7528fs-extra\u5e93\u3002\u4e3b\u8981\u5b9e\u73b0\u4e09\u4e2a\u63a5\u53e3\uff0c\u6587\u4ef6\u4e0a\u4f20\u63a5\u53e3\uff0c\u6587\u4ef6\u5408\u5e76\u63a5\u53e3\u548c\u68c0\u9a8c\u6587\u4ef6\u63a5\u53e3\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ \u4e0a\u4f20\u7684\u5207\u7247\u6587\u4ef6\u7684\u5b58\u50a8\u8def\u5f84\nconst ALL_CHUNKS_PATH = path.resolve(__dirname, 'chunks')\n\/\/ \u5207\u7247\u5408\u5e76\u5b8c\u6210\u540e\u7684\u6587\u4ef6\u5b58\u50a8\u8def\u5f84\nconst UPLOAD_FILE_PATH = path.resolve(__dirname, 'public\/files')\n\n\/**\n * \u6587\u4ef6\u4e0a\u4f20\u63a5\u53e3\n *\n *\/\napp.post('\/upload', async (req, res) => {\n    const multipartyForm = new multiparty.Form()\n    multipartyForm.parse(req, async (err, fields, files) => {\n        if (err) {\n            res.send({\n                code: 0,\n                message: '\u6587\u4ef6\u5207\u7247\u4e0a\u4f20\u5931\u8d25',\n            })\n            return\n        }\n        \/\/ \u524d\u7aef\u53d1\u9001\u7684\u5207\u7247\u6587\u4ef6\u4fe1\u606f\n        const [file] = files.file\n        \/\/ \u524d\u7aef\u53d1\u9001\u7684\u5b8c\u6574\u6587\u4ef6\u540d fileName \u548c\u5206\u7247\u540d chunkName\n        const {\n            fileName: [fileName],\n            chunkName: [chunkName],\n        } = fields\n        \/\/ \u5f53\u524d\u6587\u4ef6\u7684\u5207\u7247\u5b58\u50a8\u8def\u5f84\uff08\u5c06\u6587\u4ef6\u540d\u4f5c\u4e3a\u5207\u7247\u7684\u76ee\u5f55\u540d\uff09\n        const chunksPath = path.resolve(ALL_CHUNKS_PATH, fileName)\n        \n        \/\/ \u5224\u65ad\u5f53\u524d\u6587\u4ef6\u7684\u5207\u7247\u76ee\u5f55\u662f\u5426\u5b58\u5728\n        if (!fse.existsSync(chunksPath)) {\n            \/\/ \u521b\u5efa\u5207\u7247\u76ee\u5f55\n            fse.mkdirSync(chunksPath)\n        }\n        \/\/ \u5c06\u524d\u7aef\u53d1\u9001\u7684\u5207\u7247\u6587\u4ef6\u79fb\u52a8\u5230\u5207\u7247\u76ee\u5f55\u4e2d\n        await fse.move(file.path, `${chunksPath}\/${chunkName}`)\n        res.send({\n            code: 1,\n            message: '\u5207\u7247\u4e0a\u4f20\u6210\u529f',\n        })\n    })\n})\n\n\/**\n * \u5408\u5e76\u5207\u7247\u63a5\u53e3\n *\n *\/\napp.post('\/merge', async (req, res) => {\n    \/\/ \u83b7\u53d6\u524d\u7aef\u53d1\u9001\u7684\u53c2\u6570\n    const { chunkSize, fileName } = req.body\n    \/\/ \u5f53\u524d\u6587\u4ef6\u5207\u7247\u5408\u5e76\u6210\u529f\u540e\u7684\u6587\u4ef6\u5b58\u50a8\u8def\u5f84\n    const uploadedFile = path.resolve(UPLOAD_FILE_PATH, fileName)\n    \/\/ \u627e\u5230\u5f53\u524d\u6587\u4ef6\u6240\u6709\u5207\u7247\u7684\u5b58\u50a8\u76ee\u5f55\u8def\u5f84\n    const chunksPath = path.resolve(ALL_CHUNKS_PATH, fileName)\n    \/\/ \u8bfb\u53d6\u6240\u6709\u7684\u5207\u7247\u6587\u4ef6\uff0c\u83b7\u53d6\u5230\u6587\u4ef6\u540d\n    const chunksName = await fse.readdir(chunksPath)\n    \/\/ \u5bf9\u5207\u7247\u6587\u4ef6\u540d\u6309\u7167\u6570\u5b57\u5927\u5c0f\u6392\u5e8f\n    chunksName.sort((a, b) => a - 0 - (b - 0))\n    \/\/ \u5408\u5e76\u5207\u7247\n    const unlinkResult = chunksName.map((name, index) => {\n        \/\/ \u83b7\u53d6\u6bcf\u4e00\u4e2a\u5207\u7247\u8def\u5f84\n        const chunkPath = path.resolve(chunksPath, name)\n        \/\/ \u83b7\u53d6\u8981\u8bfb\u53d6\u5207\u7247\u6587\u4ef6\u5185\u5bb9\n        const readChunk = fse.createReadStream(chunkPath)\n        \/\/ \u83b7\u53d6\u8981\u5199\u5165\u5207\u7247\u6587\u4ef6\u914d\u7f6e\n        const writeChunk = fse.createWriteStream(uploadedFile, {\n            start: index * chunkSize,\n            end: (index + 1) * chunkSize,\n        })\n        \/\/ \u5c06\u8bfb\u53d6\u5230\u7684 readChunk \u5185\u5bb9\u5199\u5165\u5230 writeChunk \u5bf9\u5e94\u4f4d\u7f6e\n        readChunk.pipe(writeChunk)\n\n        return new Promise(resolve => {\n            \/\/ \u6587\u4ef6\u8bfb\u53d6\u7ed3\u675f\u540e\u5220\u9664\u5207\u7247\u6587\u4ef6(\u5fc5\u987b\u8981\u5c06\u6587\u4ef6\u5168\u90e8\u5220\u9664\u540e\uff0c\u624d\u80fd\u5916\u5c42\u6587\u4ef6\u5939)\n            readChunk.on('end', () => {\n                fse.unlinkSync(chunkPath)\n                resolve()\n            })\n        })\n    })\n    \/\/ \u7b49\u5230\u6240\u6709\u5207\u7247\u6587\u4ef6\u5408\u5e76\u5b8c\u6210\uff0c\u4e14\u6bcf\u4e00\u4e2a\u5207\u7247\u6587\u4ef6\u90fd\u5220\u9664\u6210\u529f\n    await Promise.all(unlinkResult)\n\n    \/\/ \u8bfb\u53d6\u6240\u6709\u7684\u5207\u7247\u6587\u4ef6\uff0c\u83b7\u53d6\u5230\u6587\u4ef6\u540d\n    const chunksNameTemp = await fse.readdir(chunksPath)\n\n    if (chunksNameTemp.length === 0) {\n        \/\/ \u5220\u9664\u5207\u7247\u6587\u4ef6\u6240\u5728\u76ee\u5f55\n        fse.rmdirSync(chunksPath)\n        res.send({\n            code: 1,\n            message: '\u6587\u4ef6\u4e0a\u4f20\u6210\u529f',\n        })\n    }\n})\n\n\/**\n * \u6821\u9a8c\u6587\u4ef6\u63a5\u53e3\n *\/\napp.post('\/verify', async (req, res) => {\n    \/\/ \u83b7\u53d6\u524d\u7aef\u53d1\u9001\u7684\u6587\u4ef6\u540d\n    const { fileName } = req.body\n    \/\/ \u83b7\u53d6\u5f53\u524d\u6587\u4ef6\u8def\u5f84\uff08\u5982\u679c\u4e0a\u4f20\u6210\u529f\u8fc7\u7684\u4fdd\u5b58\u8def\u5f84\uff09\n    const filePath = path.resolve(UPLOAD_FILE_PATH, fileName)\n    \/\/ \u5224\u65ad\u6587\u4ef6\u662f\u5426\u5b58\u5728\n    if (fse.existsSync(filePath)) {\n        res.send({\n            code: 1,\n            message: '\u6587\u4ef6\u5df2\u5b58\u5728\uff0c\u4e0d\u9700\u8981\u91cd\u65b0\u4e0a\u4f20',\n        })\n        return\n    }\n    \/\/ \u65ad\u70b9\u7eed\u4f20\uff1a\u5224\u65ad\u6587\u4ef6\u662f\u5426\u6709\u4e0a\u4f20\u7684\u4e00\u90e8\u5206\u5207\u7247\u5185\u5bb9\n    \/\/ \u83b7\u53d6\u8be5\u6587\u4ef6\u7684\u5207\u7247\u6587\u4ef6\u7684\u5b58\u50a8\u76ee\u5f55\n    const chunksPath = path.resolve(ALL_CHUNKS_PATH, fileName)\n  \n    \/\/ \u5224\u65ad\u8be5\u76ee\u5f55\u662f\u5426\u5b58\u5728\n    if (fse.existsSync(chunksPath)) {\n        \/\/ \u76ee\u5f55\u5b58\u5728\uff0c\u5219\u8bf4\u660e\u6587\u4ef6\u4e4b\u524d\u6709\u4e0a\u4f20\u8fc7\u4e00\u90e8\u5206\uff0c\u4f46\u662f\u6ca1\u6709\u5b8c\u6574\u4e0a\u4f20\u6210\u529f\n        \/\/ \u8bfb\u53d6\u4e4b\u524d\u5df2\u4e0a\u4f20\u7684\u6240\u6709\u5207\u7247\u6587\u4ef6\u540d\n        const uploaded = await fse.readdir(chunksPath)\n        res.send({\n            code: 0,\n            message: '\u8be5\u6587\u4ef6\u6709\u90e8\u5206\u4e0a\u4f20\u6570\u636e',\n            uploaded,\n        })\n        return\n    }\n\n    res.send({\n        code: 0,\n        message: '\u6587\u4ef6\u672a\u4e0a\u4f20\u8fc7',\n        uploaded:[]\n    })\n})\n<\/pre>\n\n\n\n<p><strong>03 \u603b\u7ed3<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u5c0f\u840c\u5199\u5b8cDemo\u5e76\u6ca1\u653e\u677e\uff0c\u5f88\u591a\u529f\u80fd\u8fd8\u9700\u8981\u5b8c\u5584\u3002\u5982\u5927\u6587\u4ef6\u5207\u7247\u4e0a\u4f20\u5207\u7247\u540d\u7528\u7684\u7d22\u5f15\u53f7\uff0c\u6b63\u5f0f\u9879\u76ee\u5e94\u8be5\u751f\u6210hash\u7801\u66f4\u52a0\u7a33\u59a5\u3002\u4e0a\u4f20\u5207\u7247\u6ca1\u6709\u8003\u8651\u5e76\u53d1\u4e0a\u4f20\uff0c\u540e\u671f\u5e94\u8be5\u4f7f\u7528pLimit\u5e93\u4f18\u5316\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u674e\u5c0f\u840c\u540c\u5b66\u7ecf\u8fc7\u4e0a\u6b21\u9762\u8bd5\u5931\u8d25\u540e\uff0c\u52aa\u529b\u63d0\u5347\u81ea\u5df1\u6280\u672f\uff0c\u7ec8\u4e8e\u5165\u804c\u4e00\u5bb6\u8f6f\u4ef6\u516c\u53f8\u3002\u516c\u53f8Leader\u7ed9\u5c0f\u840c\u5206\u914d\u4e86\u4e00\u4e2a\u4e0a\u4f20\u89c6\u9891 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/15374"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=15374"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/15374\/revisions"}],"predecessor-version":[{"id":15386,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/15374\/revisions\/15386"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=15374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=15374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=15374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}