From 6a8ac736add10e298a25e9b91f03ddedc3e0ec0d Mon Sep 17 00:00:00 2001 From: Marten Heinrich Date: Tue, 9 Aug 2022 11:56:29 +0200 Subject: [PATCH 1/3] Fix breaking changes with new busboy version - No more constructor - Truncated flags, encoding, and mime type information have been consolidated into a single object passed to the event handlers See: https://github.com/mscdex/busboy/issues/266 --- extract.js | 7 ++++--- package.json | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/extract.js b/extract.js index 18e614e..b3ff678 100644 --- a/extract.js +++ b/extract.js @@ -8,8 +8,9 @@ module.exports = function (req, dest, fnDestFilename, opts = {}) { let files = [] let fields = {} - let busboy = new Busboy(Object.assign({}, opts, {headers: req.headers})) - busboy.on('file', (fieldname, fileStream, filename, encoding, mimetype) => { + let busboy = Busboy(Object.assign({}, opts, {headers: req.headers})) + busboy.on('file', (fieldname, fileStream, info) => { + const { filename, encoding, mimeType } = info; if (!filename) return fileStream.resume() files.push(new Promise(function (resolve, reject) { @@ -23,7 +24,7 @@ module.exports = function (req, dest, fnDestFilename, opts = {}) { rs.fieldname = fieldname rs.filename = filename rs.encoding = encoding - rs.mimetype = mimetype + rs.mimetype = mimeType resolve(rs) }) diff --git a/package.json b/package.json index 7ad00ab..40c744c 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,6 @@ }, "dependencies": { "append-field": "^1.0.0", - "busboy": "^0.2.14" + "busboy": "^1.6" } } From 71a44dd81cef7d4209ae204f36de1eef398da8ea Mon Sep 17 00:00:00 2001 From: Marten Heinrich Date: Tue, 9 Aug 2022 11:57:35 +0200 Subject: [PATCH 2/3] Bump Version to 1.6.0 ...like busboy package --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 40c744c..46161f8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "koa-busboy", - "version": "1.2.0", + "version": "1.6.0", "description": "Koa - Upload files with busboy", "main": "index.js", "scripts": { From 485136de6b41abef7986c6bd5dc6ecd87d377b89 Mon Sep 17 00:00:00 2001 From: Marten Heinrich Date: Tue, 9 Aug 2022 13:20:04 +0200 Subject: [PATCH 3/3] Use close event instead of finish of busboy See: https://github.com/mscdex/busboy/issues/266 --- extract.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extract.js b/extract.js index b3ff678..e0a53a5 100644 --- a/extract.js +++ b/extract.js @@ -19,7 +19,7 @@ module.exports = function (req, dest, fnDestFilename, opts = {}) { fileStream.pipe(fs.createWriteStream(tmpPath)) .on('error', reject) - .on('finish', () => { + .on('close', () => { let rs = fs.createReadStream(tmpPath) rs.fieldname = fieldname rs.filename = filename @@ -38,7 +38,7 @@ module.exports = function (req, dest, fnDestFilename, opts = {}) { appendField(fields, name, value) }) - busboy.on('finish', () => { + busboy.on('close', () => { if (files.length) { Promise.all(files) .then(files => resolve({ fields, files }))