rkusa / koa-formidable Goto Github PK
View Code? Open in Web Editor NEWFormidable middleware for Koa
License: MIT License
Formidable middleware for Koa
License: MIT License
Add example on how to use events
https://github.com/felixge/node-formidable#events
and .File
https://github.com/felixge/node-formidable#formidablefile
console.log('start upload');
let newPath = '';
const form = new require('formidable').IncomingForm();
form.encoding = 'utf-8';
form.uploadDir = AVATAR_PATH;
form.keepExtensions = true;
form.maxFieldsSize = 2 * 1024 * 1024;
form.on('fileBegin', function(name, file) {
console.log(name, file);
console.log('type:', file.fulAvatar.type);
const avatarName = UUID.v4() + '.' + extName;
newPath = form.uploadDir + avatarName;
file.path = newPath;
});
form.on('aborted', function() {
console.log('aborted');
});
form.on('end', function() {
console.log('end');
});
form.on('error', function(err) {
console.log(error);
});
const result = yield formidable.parse(form, this.request);
the 'fileBegin', 'aborted', 'end', all of these events do not work. How to fix it?
hi
everything is in the title, can t get it working
just doing a simple
var form = yield formidable.parse(this);
console.log(form)
form.on('progress', function(bytesReceived, bytesExpected) {
console.log(bytesReceived, bytesExpected)
});
TypeError: form.on is not a function
how can we do please?
thanks
Other than that looks good.
From #koajs IRC:
<iliakan> what is the better place to parse POST: this.req.body OR this.request.body ?
<jongleberry> i put still in .request
<jongleberry> because that is scoped to the koa app
.write(string, encoding, offset, length) is deprecated. Use write(string[, offset[, length]][, encoding]) instead.
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.