dominhhai / koa-busboy Goto Github PK
View Code? Open in Web Editor NEWUpload files with Busboy
Home Page: https://www.npmjs.com/package/koa-busboy
License: MIT License
Upload files with Busboy
Home Page: https://www.npmjs.com/package/koa-busboy
License: MIT License
https://github.com/mscdex/busboy#examples show how to extract data:
busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
console.log('File [' + fieldname + ']: filename: ' + filename + ', encoding: ' + encoding + ', mimetype: ' + mimetype);
file.on('data', function(data) {
console.log('File [' + fieldname + '] got ' + data.length + ' bytes'); // <-- HERE
});
file.on('end', function() {
console.log('File [' + fieldname + '] Finished');
});
});
Is it possible to implement this feature in this package?
Hi @dominhhai, there are diffrences between the version in git and the version on npm. Can you please publish the latest version on npm. This would be enhance the health of the package on npm. Thanks.
Add feature dynamic dest like depend on post data, code like
const uploader = async ctx => {
console.log(ctx.request.body)
const {path} = ctx.request.body
return await busboy({
dest: path,
fnDestFilename: (fieldname, filename) => filename
})
}
I've encountered an unhandled promise rejection that I was able to track down and fix with the following patch.
diff --git a/extract.js b/extract.js
index 18e614e..e657bc3 100644
--- a/extract.js
+++ b/extract.js
@@ -27,7 +27,7 @@ module.exports = function (req, dest, fnDestFilename, opts = {}) {
resolve(rs)
})
- }))
+ }).catch(reject))
})
busboy.on('field', (name, value) => {
I think it happened when there was a problem with GlusterFS. I was able to reproduce it using SSHFS, but it's not simple.
There is a Promise.all(files).catch(reject)
further down, but it's too late.
Would you make saving files to disk optional? I'd like to use just the readstreams returned by busboy for the various files and do something else with them rather than save them to disk.
Thanks for the lib @dominhhai! I have had to fork it just to work around the fact that the actual filename that gets written to disk on the server is opaquely modified:
https://github.com/dominhhai/koa-busboy/blob/master/extract.js#L16
It would be ideal if this was configurable - in my particular use case my filenames are already guaranteed to be unique and I don't really want to have to parse the fileReadStream.path
to work out what the final filename is on disk. I also find it unintuitive that fileReadStream.filename
shows the original filename and not the final, modified one.
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.